We've seen a lot of people get confused by {{if}} vs {{compare}}. {{if}} is used to check whether a field has a value or not, whereas {{compare}} is used to check whether a field has one value or another value.
For example, using {{if}} in a statement to check a field has one value or another if a statement is true (in this case, the vendor is ACME Anvils) will give you an error like this:
handlebars_template_parse_error
'Failed to generate field value from template: {{#if Vendor="ACME Anvils"}} "Wile E. Coyote" {{else}} "Road Runner" {{/if}}'
Check out our Handlebars helper reference for more information on handlebars {{compare}}, {{if}}, and other handlebars expressions! Let us know if you have other handlebars questions!
Thanks, @psaadmin (aka Jim!) And thank you for all of your help in strengthening our community! We're in the process of going through customer questions on handlebars and will be getting more of these out as soon as we can! If you have any tips and tricks, please share!
Hi @courtneyjordan, how would this look for a multi-nested statement with 'AND' functionality?
For example: - If sales_term_months = 36 AND Billing_Frequency = Annual THEN Invoice_Count = 3 otherwise... - If sales_term_months = 12 AND Billing_Frequency = Annual THEN Invoice_Count = 1 otherwise... - If sales_term_months = 12 AND Billing_Frequency = semi-Annual THEN Invoice_Count = 2 otherwise... - Invoice_Count = unknown
The "low-code" solution simply doesn't offer, to my knowledge, the familiar elseif() or if(x && y) or select-case logic.
Perhaps it will help to see it with whitespace (which you'd want to remove for real-world JSON or import mapping) to understand how the nested statements are structured.
Hello, @ugenejude. I confirmed the nested approach just above with a support supervisor, and it applies in your case as well. There is no "or" allowed within {#compare}, {#contains}, or {#if} – by design.
There might be an easier approach, though, depending on what you're trying to accomplish. Could you perhaps apply this logic in import mapping, in a static lookup "table?" For example,
US = X CA = X UK = X
Then, set the default value to Y for everything else? That's assuming you're not trying to build a JSON or XML template in an Advanced field editor, in which case handlebars or JavaScript would be your best and only approaches.
Thank you for the quick response Stephen. Our else requirement further checks other fields from the payload. So the intention was to check for feasibility of an OR to at least shorten the compare block. The information yo have clarified that part. Thanks again.
I am using the compare function on three export fields on import mapping step into NetSuite. When I run the flow I get errors that the values for these fields are not set.
Following is my source export data from a custom REST API.
I checked with one of our handlebars experts. He says the issue is that you're using wildcards in your expression. You'll need to specify the exact indices for the values you want to match. I hope that helps!
That seems a bit strange. The same kind of expression ( result.styles[*].field ) is used to map other fields and these are working fine. The difference here is that I am using the #compare function. So, If I understand it correctly, the expert is saying that the handlebars won't accept wildcard while "standard" filed mappings work with wildcard? I am using a similar expression on record lookup to ignore existing records. Also, when processing multiple records as part of import mapping, how can one give specific indexes while doing the mapping?