Using Property Values in Multiply Operator

InsightStudio
Contributor | Gold Partner

Hey Team!

 

We're working on a quote template and trying to surface a modified Amount Total that includes a calculation using a tax rate that's a custom property on the deal. Currently only limited experience in working with HubL

 

I'm running into a syntax error, " Invalid argument in 'multiply': 1st argument with value '{{deal.tax_rate}}' must be a number"

 

I'm thinking that this wouldn't be an issue if it were publishable because deal.tax_rate is actually a number when it populates... but I can't publish with the syntax error. 

Here's the code: 

<h3>Total {{ QUOTE_TOTAL|multiply(deal.tax_rate)|format_currency(LOCALE, CURRENCY) }}</h3>

 

Example value for deal.tax_rate would be 4.5

 

End goal is multiplying the amount by 1.(tax_rate) to end up with a new total that reflects the previous total plus the appropriate tax, but I figure if I can get the variable to work in this multiple function then I can always pass 1.045 instead of 4.5 for example into the deal property, or do a calculated property. 

 

Any help/guidance is appreciated!

0 Upvotes
4 Replies 4
dennisedson
Community Manager

Hey @InsightStudio !

If you take a look at this developer documentation, you can see all of the filters available.  You should look specifically at the int filter.

 

Hope this helps!

Thanks,

Dennis



Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
Kevin-C
Recognized Expert

Hey @InsightStudio 

 

That error means that the argument you passed to the multiply filter isn't a number.

 

If it looks like a number I would check for spaces or hidden characters.

 

It's important to know that Hubl / Jinja will attempt to coerce values to an appropriate primative in order to use them, but it won't remove the spaces locking the variable to a string class. This is alsp probably the reason the HS team didn't create a parse filter. See my example below:

"123" === 123, "12.3" == 12.3, and "1.23" === 1.23

" 123" != 123, "12.3 " != 12.3, and "1. 23" != 1.23.

 

EDIT:

A simple test (very simple) is to print the value with a character on either side of the expression. This will allow you to visually see if their are any spaces.

{% set your_variable = 23.4 %}
.{{ your_variable }}.

If it prints ". 23.4." or ".23.4 .", you can see the spaces.

Again very simple test.

 

 

@dennisedson suggestion of |int would work with one serious drawback. Integer refers to a whole number. That means the |int filter will strip any decimal point from the number. Not ideal when dealing with taxes!

 

TL;DR

My suggestion!

Use replace to sanitize the string of any spaces!

 

 

 

 

 

<h3>Total {{ QUOTE_TOTAL|multiply(deal.tax_rate|replace(' ','')|format_currency(LOCALE, CURRENCY) }}</h3>

 

 

 

 

 

 

InsightStudio
Contributor | Gold Partner

Thanks Kevin! Does this work in a Quote template on your end? I still get an error thrown in Design Manager because the property token isn't a number (it doesn't look past the token to see what an example value would be as far as I can tell, it just says 'hey, you gotta pass a number here and that (the token) isn't a number)

0 Upvotes
Kevin-C
Recognized Expert

Hey @InsightStudio 

 

I cannot test this ATM, not sure I can replicate your situatiom.

 

Have you tried using the "pprint" filter to get more info about the object? Ideally this will tell you what kind of object the property token is. That should reduce the number of situations you'll have to test.

0 Upvotes