- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 03:16 PM
I'm developing a client script in my PDI on the Incident Table. When a user changes the state to canceled (value = 8), then currency 1 field gets auto populated with the absolute value of currency 2 field. Screenshot below:
Below is my Client Script that I'm using that works because it is auto populating the value, but not the absolute value. When I add Math.abs(), what's returning is NaN. So I commented that code out. Any idea what I'm doing wrong?
Much thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 08:51 AM
Updated and working Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var abc = Math.abs(parseFloat(g_form.getValue('u_currency_type').split(';')[1].replace(/,/g, "")));
alert(abc);
g_form.setValue('u_cur','USD'+';'+abc);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 08:36 PM
Hi @Phong Lo,
I think you need to convert the value in the Currency 2 field to a numeric format first before performing the Math.abs() operation on it. Could you please try using the following line of code in your Client Script and check if it works?
var absolute_value = Math.abs(parseFloat(currency_2_value));
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 06:45 AM
It's still showing up as NaN. This is what 'currency_2_value' is showing up as:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 08:46 PM - edited 02-06-2024 08:48 PM
Hello @Phong Lo ,
You should change step number 8 as
var absolute_value = Math.abs(parseFloat(currency_2_value));
because at step number 7, currency_2_value getting a string value. We should parse it to float/integer to work with Math functions.
Please mark my answer as helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 06:46 AM
It's still showing up as NaN. This is what 'currency_2_value' is showing up as: