- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 07:25 AM
Hi All,
I have the following script that compares if the repair cost of a machine is greater than the value of the laptop and then returns if the laptop should be disposed or repaired.
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') { return; } var value = g_form.getValue('u_net_book_value'); var repair = g_form.getValue('u_repair_cost____'); if (repair > value) { g_form.setValue('u_dispose_ci_', 'Dispose'); } else { g_form.setValue('u_dispose_ci_', 'Repair'); } }
The issue i have is that sometimes it's advising me to repair a laptop even though it should be disposed.
For example in the below screenshot. The laptop is worth £33.81 and the repair cost is £10.000. it should tell me to dispose but it's not.
I have tried setting "Net Book Value ( £)" & "Repair Cost ( £)" to decimal and integer but its makes no difference.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 09:13 AM
Ok. Just tried below one and it worked.
Please try this as well
var value = parseInt(g_form.getValue('u_price').toString().replace(',',''));
var repair = parseInt(g_form.getValue('u_price_2').toString().replace(',',''));
replace the variables with your variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 09:05 AM
parseInt now alerts both as a type of number but:
A repair cost of 100,000 is alerted as 100.
A repair cost of 10,000 is alerted as 10.
It's like any repair cost bigger than 999 starts messing up...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 09:13 AM
Ok. Just tried below one and it worked.
Please try this as well
var value = parseInt(g_form.getValue('u_price').toString().replace(',',''));
var repair = parseInt(g_form.getValue('u_price_2').toString().replace(',',''));
replace the variables with your variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 09:23 AM
Thanks RKumar02,
That seems to have worked but can you explain how? and why it did not work in the first place?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 09:30 AM
Good to hear that. ServiceNow adds comma as separator for numbers and when you pick those values they are returns as it is(with comma). Probably this is the issue they need to fix.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 08:54 AM
Are these fields set as Currency data type?