Nested Compare Handlebar Expression

I'm trying to write a handlebar expression to calculate and populate the amount a specific way based on what product is being used in Salesforce.

The logic would be

if the product code = TC001 then I want the amount to be 20% of the TCV

if the product code = TC002 then I want the amount to be 80% of the TCV

Otherwise I just want it to take the TCV.

what I have to far is {{#compare OpportunityLineItems.[*].Product_Code__c "==" "TC001"}} {{multiply ".80" TCV}} {{else}}

{{#compare OpportunityLineItems.[*].Product_Code__c "==" "TC002"}} {{multiply ".20" TCV}} {{else}}

{{TCV}} {{/compare}}

Hi Anna,

I slightly modified what you created since the idea is already there. You can try the ones below:

{{#compare OpportunityLineItems.[*].Product_Code__c "==" "TC001"}}{{multiply TCV ".80"}}{{else}}{{TCV}}{{/compare}}

{{#compare OpportunityLineItems.[*].Product_Code__c "==" "TC002"}}{{multiply TCV ".20"}}{{else}}{{TCV}}{{/compare}}

Hope this works out for you!

That didn't quiet work because it was giving me multiple outputs. I ended up with this

{{#compare OpportunityLineItems.[*].Product_Code__c "==" "TC001"}}{{multiply TCV ".80"}}{{/compare}}

{{#compare OpportunityLineItems.[*].Product_Code__c "==" "TC002"}}{{multiply TCV ".20"}}{{else}}{{TCV}}{{/compare}}

but now I am getting an error that says I have more than 5 decimal places

Hello Anna,

If you're using these two compare handlebars in the same mapping, you can combine the compare statements as well as add a tofixed handlebar to control the number of decimal places.

Here is a solution that may work for you.


{{#compare OpportunityLineItems.[*].Product_Code__c "==" "TC001"}}{{toFixed (multiply TCV ".80") 2}}{{else compare OpportunityLineItems.[*].Product_Code__c "==" "TC002"}}{{toFixed (multiply TCV ".20") 2}}{{else}}{{TCV}}{{/compare}}

Hope this helps.