onChange Script (revert back)

Graham18
Giga Expert

Hi All,

When using an onChange client script for example a true false field, how do you make it revert back when the value has been changed back to its original.

As it stands my script will work but wont revert back when the value has changed back to what it was before.

i'm sure its something simple

Regards,

Graham

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Graham,



You can use the oldValue at client script side to set the previous value.


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if (isLoading || newValue == 'Major Incident, true') {


return;


}



g_formSetValue('Priority', 1);


return


}


}



This is what i have so far, what i need is when the 'Major Incident?' check box is unchecked the Prioirty returns to its old value.



not sure how to do this, any help would be appreciated



Thanks.


You have to write one more client script on priority field.


Logic will be something like if the newvalue and oldvalue is not same and the checkbox is unchecked then set the priority to the oldvalue.



Please let me know if you have any questions.


So are you saying that for any field you want to get the 'oldValue' for you need to have a script to capture that?