how to sum two currency values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 10:59 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 11:15 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 12:48 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 11:20 PM
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 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 12:52 AM
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