- 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 07:37 AM
Can I assume, based on the bottom line of your post, that Net Book Value and Repair Cost are currency variables?
My first thought is that these values aren't being compared as numbers, so maybe try updating lines 6 & 7 to the following:
var value = parseFloat(g_form.getValue('u_net_book_value'));
var repair = parseFloat(g_form.getValue('u_repair_cost____'));
Let me know if you have any luck. Cheers, Adam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 07:42 AM
Hi Adam,
At present they are both set to interger.
I tried parseFloat but it made no difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 07:52 AM
Hi Alex,
Never mind. I'm guessing also that your client script is running against the u_repair_cost____ field?
If so, how about changing line 7 to:
var repair = newValue
If this still doesn't work, add these two lines underneath line 7 and let me know what the output is when you run the form (they will popup as alert boxes):
alert("value\n" + typeof(value) + "\n" + value);
alert("repair\n" + typeof(repair) + "\n" + repair);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 08:10 AM
Hi Adam,
Using parseFloat they both returned a type of number.
But i can now see what the problem is.
When entering a repair cost of "1,000,000" the alert brought back 1.
When entering a repair cost of "10000" the alert brought back 10.