Is there a way to compare a text field to a number...
# general
l
Is there a way to compare a text field to a number in advanced pdf? for some reason, the standard amount paid field on the invoice is not a number but a hash+string, etc. I tried a lot of the conversions from the freemarker website but I can’t make it work. #if record.amountpaid?string != 0.00?string #if record.amountpaid?number != 0.00?number #if record.amountpaid gt 0.00 #if record.amountpaid?string.number != ‘0.00’?string.number Left hand operand is a sequence+hash+string (wrapper: com.netledger.templates.model.EmptyModel). Right hand operand is a number (wrapper: f.t.SimpleNumber). The blamed expression: ==> record.amountpaid = 0 [in template “template” at line 147, column 12]
I'd expect this to work:
Copy code
<#if record.amountpaid?number gt 0>
l
Weirdly enough. I’m still getting an error: Can’t convert this string to number: “” The blamed expression: ==> record.amountpaid?number [in template “template” at line 147, column 6] ---- FTL stack trace (“~” means nesting-related): - Failed at: #if record.amountpaid?number gt 0 [in template “template” at line 147, column 1] ----
d
try
<#if record.amountpaid != '' && record.amountpaid?number gt 0>
n
or ?has_content instead of !=''
l
@David B i will try that in the next few hours. Thanks
@NElliott it always has a default value of 0.00, so I can't use 'has content' but thanks
n
then I imagine !='' would not work either 🤷🏻‍♂️ interested to know if it does though.
d
tested,
record.amountpaid
includes the currency symbol, at least for me. Hence it fails the
?number
conversion. When you save the template, NetSuite populates the fields with dummy data for testing. String fields like amountpaid get populated (sometimes?) with an empty string, which is why you get the error
Can't convert this string to number: ""
if you 'submit anyway' and print an invoice, you instead see the error
Can't convert this string to number: "$0.00"
my solution was to strip the currency symbol using regex. like this:
record.amountpaid?has_content && record.amountpaid?replace('[^\\d.]','','r')?number != 0
you could maybe implicitly check
amountpaid != '$0.00'
, but you're assuming the currency symbol will always be
$
you could instead slice off the first character to remove the currency symbol ($,£,¥,€,etc), but that presumes the currency has a symbol. *edit. like
amountpaid[1..]
IIRC, some currencies just use the 3-digit ISO currency code (e.g. "USD"). I also think this is controlled by a NetSuite account setting _*edit. yes, it's a company info setting if you have one currency, otherwise against each currency record: NS Help: Customizing Currency Formats_
🙌🏻 1
l
Thank you. I really got frustrated and created a custom field to store the amount paid so I can proceed with the invoicing. But I'll try the above as I don't want to duplicate a standard field.