We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Hi Ankur,

yes! I have changed my code as below and then it worked.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var price = g_form.getValue('u_price_over_location');
var currency_code = price.split(';')[0];
price = g_form.getValue('u_price_over_location.display').replace(/,/g, "");
var float_price = parseFloat(price);

var gst = 0.28;

var gst1 = parseFloat(gst);

var price1 = float_price*gst1;

if (newValue == '1') {
g_form.setValue('u_added_gst', currency_code + ';'+price1);
}

}

 

Thanks,

Sandeep Reddy Lebaka.

Hi Sandeep,

Can you also mark answer as correct and helpful.

Regards

Ankur

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

Hi

Thanks for your support Ankur.

Regards,

Sandeep.