'How to compare a field value with a number in an email template
I need to be able to show a line of text if the total value of an invoice is less than 5,000. I tried the below code but am getting an error:
<#if transaction.total < 5000>Total is less than 5K</#if>
The error I am getting is the following:
Can't compare values of these types. Allowed comparisons are between two numbers, two strings, two dates, or two booleans.Left hand operand is a hash+string(wrapper: com.netledger.model.StringModel)..Right hand operand is a number (weapper:f.t.SimpleNumber)..The blamed expression: ==> transaction.otal < 1000 [in template "content" at line 14, column 6]..----,FTL stack trace ("~" means nesting-related): Failed at: #if transaction.total %lt; 1000
How can I fix this?
Edited to add complete error message.
Solution 1:[1]
The error message indicates the code you show is not the code that is running:
From the error the template has transaction.otal not transaction.total
Solution 2:[2]
that's odd. I've looked through my templates and realized I've never compared any transaction currency fields. They do work as numbers though so you probably just need to coerce them a little. Note you don't need to escape a less than sign
try:
<#if (0+transaction.total) < 5000>Total is less than 5K</#if>
or
<#if transaction.total?number < 5000>Total is less than 5K</#if>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bknights |
| Solution 2 | bknights |
