Issue Comparing Values

arobertson
Tera Guru

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.

Capture.PNG

 

I have tried setting "Net Book Value ( £)" & "Repair Cost ( £)" to decimal and integer but its makes no difference.

1 ACCEPTED SOLUTION

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


View solution in original post

18 REPLIES 18

Have these fields ever been anything other than Integer? I mean, I've noticed issues when trying to change the data type that a   specific field holds, as the underlying field in the database expects a certain type.


Hi Adam,



I have also expreicned this before thats what i complely deleted both dictonary entrys and then re-added them both as interger.


If they are integer, then you won't be able to store the decimals. The system may be cropping what you've entered or something else similarly strange. Have you tried using currency variables for this?


Hi Alex,


"Net Book Value" field can not be an integer type as it is accepting float value. Had it been an integer field ServiceNow wouldn't have allowed so.