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.

How to Multiply currency field with integer value?

Sandeep Reddy L
Tera Contributor

Hi,

I have three fields

  1. Location (u_location)
  2. Ex-showroom Price(u_price_over_location)
  3. Added GST(u_added_gst)

I have written onChange Client script, location is the field I have selected as onChange Field. Based on the location, "added GST" field should get populated with 28% of "Ex-Showroom Price". But my code was not working where did I made mistake.

here is the code i have written:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var price = g_form.getValue('u_price_over_location');
var gst = 0.28;
var price1 = gst*price;
if (newValue == '1') {
g_form.setValue('u_added_gst', price1);
}

}

1 ACCEPTED SOLUTION

Hi Sandeep,

Can you also mark answer as correct and helpful.

Regards

Ankur

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

View solution in original post

12 REPLIES 12

Anurag Tripathi
Mega Patron
Mega Patron

convert the values using parseFloat and parseInt functions and then multiply.

-Anurag

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sandeep,

please use below code and test once; the highlighted part will give you the integer/float value

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var price = g_form.getValue('u_price_over_location').substring(4);
var gst = 0.28;
var price1 = parseFloat(gst) * parseFloat(price);
if (newValue == '1') {
g_form.setValue('u_added_gst', price1);
}

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur Bawiskar,

 

Thanks for the response. I have change my code as you suggested me, but I got an error as below.

"onChange script error: TypeError: value.indexOf is not a function function () { [native code] }".

 

and can you explain what does .substring(4); do.

Thanks,

Sandeep.

substring function is supposed to cut out a piece of a script in javascript.

Try this

 

g_form.getValue('u_price_over_location').toString().substring(4);

-Anurag