how to sum two currency values

rajeevsaraf
Tera Contributor

Hi,

 

How to sum up two currency values in client script. the currency values are being populated from hardware model table.

the challenge is different user profile pull different currency format.

Following is an example how currency are being populated

User from Germany with English language : € 1,000.56

User from Germany with German language : € 1.000,56

hence would like to have a general solution which can accept currency values of any format.

Thanks in advance.

 

Regards,

Rajeev

 

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I would suggest to use before update business rule for adding the currency fields

Don't worry about the different currency formats

Default currency values in scripts

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

this won't work because even if i use user session currency there will always be a problem with comma and dot , i.e. € 1,000.56 , € 1.000,56

 

Regards,

Rajeev

Aman Kumar S
Kilo Patron

You can simply use

var cost1 = parseFloat(g_form.getValue("price_field_1"));

var cost2 = parseFloat(g_form.getValue("price_field_2"));

g_form.setValue("cost3", cost1 + cost2 );

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

this was even not working, you may give a try on bg script

cost 1 = € 1,000.56 

cost 2  = € 2,000.56

AND

 

cost 1 = € 1.000,56 

cost 2  = € 2.000,56