
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 03:21 AM
Hi,
I have three fields
- Location (u_location)
- Ex-showroom Price(u_price_over_location)
- 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);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 09:19 PM
Hi Sandeep,
Can you also mark answer as correct and helpful.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 09:18 AM
Hi,
This is also not working. I am getting same error.
Thanks,
Sandeep Lebaka.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 04:06 AM
Hi Sandeep,
substring will give you the value i.e. USD;1435 then it would give 1435
also indexOf function we have not used so this error should not come
Do you have any other onChange script where you are using indexOf?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 09:16 AM
Hi Ankur,
No, I have not used IndexOf in any client Scripts.
when the code is static (g_form.setValue('u_added_gst','9000');), then its working without any error.
when the code is dynamic (g_form.setValue('u_added_gst',parseFloat(gst)*parseFloat(price));), then I am getting the following error. "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 10:42 AM
Hi Sandeep,
Did you try to alert the value of the multiplication?
just try to set like this
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', 'USD;'+ price1);
}
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 05:22 AM
Hi Sandeep,
Any update on this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader