Hi All, I want to know a solution for currency for...
# advancedpdf
d
Hi All, I want to know a solution for currency format in freemarker. We have estimate a drop down field on estimate with countries as values in it. Say for example if I'm creating an estimate in USD(Base currency) and I choose India from the drop down field, the estimate will be printed in INR currency. I have accomplished this using a userevent. however the problem I'm facing is the currency format. for Turkey and germany Currency the freemarker throws me an error. "Failed to get number format object for the ".##0,00" number format string: Malformed pattern ".##0,00" The blamed expression:" is there any way to format currency in freemarker
s
Are you trying to format multiple currency formats in the same document? Or, are you just trying to get a number to print correctly for the selected country? Is currency inferred from the country? Can you share the line(s) of FreeMarker code that is giving the error?
d
Thanks for the reply scott. Yes I'm trying to format multiple currency on the estimate. I got to know that the format should be ",##.00" and not ".##,00". I found on internet that we can use <#setting locale="fr"/> but even this is not working. What I'm trying to achieve is that when someone creates a fresh estimate in US subsidiary the base currency would be USD however if in pdf template field if they select INR then the script would calculate the exchange rate and I manipulate the pdf template so that it shows INR data but on estimate record the data is still in USD. So the question is that it shows everything correct except the currency format. it shows like this "12344.00" we want to show it like 12,344.00". and this format should be as per the value we select in the field "pdf template"
s
Yes, it would still be helpful to see the code. There are many ways to format currency in freemarker.
amt?currency
is the easiest way, but will always use your account’s base currency, so probably not helpful here.
nsformat_currency(amt)
may help, but only if this is a transaction and the currency is set correctly on the transaction. It sounds like you are using something else, like a country or locale setting, so again, that may not help. And yes, if you are not actually changing the currency value on the estimate from USD to something else, it will remain in USD. The easiest, and best way is to actually change the currency on the estimate if you can, then you avoid a lot of unnecessary work, as you can leverage the native currency formatting in NetSuite to do things correctly for you. Maybe you can set the currency using your user event script?
d
Yes there is an userevent script running behind the estimate. in userevent I'm calculating the exchange rate and setting it in a custom field named exchange rate. so with this field I access it in freemarker and multiply with the rate to get it into INR.
s
I guess the biggest question is, is there a reason you are not or can not set the currency on the estimate? Do you want to keep the estimate in USD, but print in a different currency?
d
Yes I want to keep it in USD but print it in different curruncies
s
Ultimately, if the estimate is in the other currency, you’ll have an exchange rate, and the GL impact will still be in your base currency, so usually you don’t need to do that. You can even display the USD amount next to the foreign currency amount in NetSuite, but just not show it on the PDF.
d
I think I'm unable to explain you the problem
s
Has your company ever used transactions in currencies other than USD before? Usually it is not a problem, all GL impact and all reports can and will remain in USD, regardless of the transaction’s currency
d
Yes we do use different currencies
we are developing this feature because it reduces the sales rep work as he don't have to create multiple estimate for the same customer in different currencies
s
Okay. Since you are presenting to thew customer in another currency, like INR, why not use that at the estimate’s currency then? Just curious, since it is by far the simplest thing to do. Anything else is going to be a lot of custom work.
But, as you said, there is a drop-down selection for country, right? So isn’t the currency known? are are you presentign them with multiple currency/payment options so they can choose?
d
because if the customer says that I want the quote in 5 different currency we will only create on quote but in USD and we will select INR in "pdf template" field then "CAD" we will select Canada in "pdf template" and so on. then ISR will only share the print outs of the estimate.
see this for an instance
here the estimate is in USD but when I select pune in the pdf template option it will print this estimate in INR values instead of USD
s
Okay. that definitely will make it harder then. The locale setting may help, since you can use it for number formatting (but not. currency formatting). You will then just need to add the correct currency symbol to the beginning or end of the formatted numbers.
d
I'm doing that as well however it shows only like this $1234
The end user wants it that also formatted. "$1,234" like this
and if I add the string?currency in freemarker then it will show me in USD format
s
right, you can’t use that, it will never work
because it will always be USD (it'
d
yes
s
the reason is that freemarker runs in NetSuite’s Java environment
d
that's my problem. How do I make the formatting of the currency based on the selection I made in the pdf template field
s
and Java has a system locale and currency, and they can only be one value, which NS sets to your account country and currency
d
ohh
s
There is no easy way. You must detect the country, and based on that, set the corretc numebr format. But you will have to add the currency symbol yourself
there is no other way, if you are not changing the transaction currency
d
ahhhh
I get it
s
You can use this:
<#setting number_format=",##0.00">
to set the number format just once, at the top of the document, based on the country selected
then use
amt?string.number
on your number values
It should use the defined number format
d
okay. what about the french currency. their format is quite the opposite
s
Well, right, that was just an example
d
okay. Thanks for this immense support. I'll have to do more R&D on my solution.
🙏
s
You’ll need something like this at the top of your template
d
but there is one problem. does this ".##0,00" works in freemarker?
s
yes, it should
d
okay I'll give it another shot right away
s
the format follows Java convention
You could combine a few countries with the same format together, too:
<#else if record.pdf_countryc?matches('US|CA', 'i')>
d
okay let me give it a shot again
I'll reply on this same thread if I get any error or success
s
okay, good luck!
d
Thank
m
If you already have a user event, you can try formatting the currency string in the user event instead of in the template
d
@michoel but that will only format one field in userevent. we have to format each and every field in the template
s
Another possibility would be to create a Suitelet script that takes an estimate internal id and perhaps creates a new estimate in the selected pdf currency, sets all of the numeric values on the new estimate, then use a custom template and two data sources to combine the numeric fields from the new estimate with the other fields from the original estimate and produces the correct PDF as output. I am not sure if you’d have to save the estimate for that to work, though. It might be work a try if other ways are not working. I use Suitelets quite a bit whenever I have to generate a PDF that requires data not available within the record being printed, since it can source in other data via searches, files, web service calls, javascript code, and other records.
d
Yeah I thought of this. as I would I have to work from scratch for this, I figured out a way in the freemarker itself. here is code that I wrote in freemarker which is running.
<#function formatCurr x> <#assign curr = 'USA'> <#if curr == 'India Quote Pune' || curr == 'India Quote Kolkata' || curr == 'India Quote Bangalore' || curr == 'Australia' || curr == 'USA' || curr == 'USA' || curr == ''> <#setting locale=number> <#setting locale="us" /> #else <#setting locale="de" /> </#if> <#return x> </#function> ${formatCurr(1234567890876)}
curr will have dynamic data
@scottvonduhn Thanks for that suitelet solution.
s
Glad you got it working
🙏 1