I have a number that is being calculated within a ...
# advancedpdf
m
I have a number that is being calculated within a PDF template and I’m having trouble displaying that number formatted to match the currency of the transaction. If we output
${item.amount}
it will format to the correct currency for the transaction. If we output
${groupTotals[item.lineuniquekey]}
, our custom calculated amount, it just outputs a straight number with no formatting. This value is being calculated in a function within the PDF template. If we try to format the calculated value with
?string.currency
it always formats as USD currency with a dollar sign, comma and decimal point. Even when the standard formatting for Euro transactions is with the Euro symbol, a space for thousands separator and a comma for the decimal separator.
?string*(",##0.00")*
returns something similiar to USD all the time. Spaces don't work in that format string so I can't even hardcode format values for different currencies. What can I do to format this number for the currency of the current transaction? Here's an example.
s
m
Yeah, I saw that article, that's where I found the ",##0.00" format string. 🙂 It works in his article for "multiple" currencies because he's only demonstrating USD and GBP which have the same format (minus the symbol). Once you go to other currencies, that format doesn't match the other line items.
n
Maybe you can condition code the formatting based on the transaction currency field which should come back as USD / GBP / EUR not ideal if there's potential for more currencies in the future but fine if static.
So in that article they check the "currencysymbol" field to assign a currency type with the physical symbol, at the point you format your values you could, presumably, check what value you have and apply the ",##0.00" format string or whatever is applicable for this currency?
s
You can try using
nsformat_currency
, as documented here: https://suiteanswers.custhelp.com/app/answers/detail/a_id/26500/#subsect_156624108232 It is, by far, the best and easiest way to ensure that any custom or computed numeric value prints the way that it would have as if it were a currency field on the transaction. Unless you are doing something that should always be in one currency, it’s best to NOT use the optional second parameter, as NetSuite will default to the transaction currency in that case.
slack bookmark 1
👍 2
m
@scottvonduhn That was exactly what I needed! Works flawlessly:
${nsformat_currency(groupTotal, record.currencysymbol)
Thank-you!!
🙌 1
s
your’e welcome, however note what i mentioned about not using the second parameter. it isn’t needed, and will default to the transaction currency anyway, so it’s best left off, except in cases where you want to override it to be something other than the transaction currency.
m
When I left out the second parameter, it formatted to USD with $0,000.00 even on a Euro transaction.
s
oh, interesting. we have not see not that behavior, it always used our transaction currency
m
It could be because I'm not using
render.transaction
and I'm using
render.renderAsPdf
and passing in data.
s
oh, that very well could be it!
m
I miss a lot of built-in transaction stuff that way. For example. It wants to print item group members when we do it this way so we have to calculate the item group total and remove the members ourselves.
s
yeah, render.transaction sets a bunch of things up by default, like the locale, currency, and date & number formats
when we use renderAsPdf, we have to set those values explicitly, so yes, I think that is the reason. IT certainly makes it harder. I have also noticed we have to XML escape urls, which doesn’t seem to be necessary when using render.transaction
m
We do too. 🙂
renderAsString()
, escape a bunch of stuff,
context.response.renderPdf(str)
. lol
s
consistency is not NetSuite’s strong suit