Format the sum of two currency fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 12:57 PM
Hi,
I have two onChange client scripts, one for the var "hardware_cost" and the secong for "installation_config_cost" and they sum to a third field. I can't get the sum mfield to properly format as US currency, with dollar signs, comma's and decimals. Here are the Scripts:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var value1 = g_form.getValue('hardware_cost').replace(/\D/g,'');
var value2 = g_form.getValue('installation_config_cost').replace(/\D/g,'');
var sum = parseFloat(value1) + parseFloat(value2);
g_form.setValue('onetime_cost_total', sum);
Here is what it returns:
How can I format the sum which is the "Onetime Cost Total." Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 03:53 PM
Can't figure it out!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 11:37 AM
@Sean Hamilton1 , did you figure it out with a simple business rule to accomplish the string formatting as a currency look?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 09:37 PM
check this link
how can i calculate two currency fields?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader