Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Format the sum of two currency fields

Sean Hamilton1
Tera Contributor

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:  

SeanHamilton1_0-1746474970474.png

How can I format the sum which is the "Onetime Cost Total."  Thanks!

7 REPLIES 7

You-Lan Bribach
Tera Contributor

Is the Onetime Cost Total a currency field? Thank you.

Sean Hamilton1
Tera Contributor

Yes I tried that, didn't work!  Our lead developer told me I need to format the sum in the script, something to that effect.

That's the other option. Please let me know if it works. Thank you.

Sure, however I don't know how to do that!