Adding currency fields on form

cre1014
Kilo Expert

I'm creating a finance application within SN, and I'm having trouble adding currency fields together and getting them to return a value into another currency field.

I haven't had too much luck in figuring out why my code doesn't work; my researched showed that there are three "elements" in the currency field that all have to be addressed when you're setting a value, but I haven't figured that out either.

To simplify my example, say I was to add a field called "Year One" and "Year Two" together and place it into a field called "Total". All of these fields are currency field all using USD. Here is how I'm currently adding them.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  if (isLoading || newValue == '') {

  return;

  }

  //get values in all of the existing currency fields

  var two = g_form.getDecimalValue('u_year_two');

  var one = g_form.getDecimalValue('u_year_one');

  //parse float method

  var total = (parseFloat(one) + parseFloat(two)).toFixed(2);

  g_form.setValue('u_total', total);

}

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee
4 REPLIES 4

The problem is that I need to do these calculations in a client script - so I can't use current.price


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

HI Caitlyn Estep



This should address your query.


Setting Currency Field values via client-side script



I hope this helps


manish123
Giga Guru

Hi All,

Could you please let me know how do I print the negative value in currency field? like $-20, $-400,$-5000 etc. Because on log message its printing with - but on field it print $20,$400,$5000 etc... 

Quick reply much appreciated