Trigger onChange on field

pdom
Mega Expert

Hi,

On change table we have a custom field called failure. I want   to trigger an OnChange event on Risk field on change of Failure field. I have created below client script but does not seem to be working. any help?

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

    if (isLoading || newValue === '') {

          return;

    }

  var temp=g_form.getControl('risk');

  temp.onChange();

}

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Padmini,



Can you give more details on where is the script defined and what is the expected outcome.


//   temp.onChange();   Can you please explain what this script line does.


Well, the background is:



I have two datalookup rule:



Rule 1 : The "Likely Faiure" and "Failure Consequence" field defines the Risk field value. The risk field is a readonly field


Rule 2 : The Risk and Impact field values define the category field value.



When the Risk field is being updated by datalookup rule, it is not triggering a UI change on Riskfield and because of this the Category value is not beilng calculated onChange of Risk value. I have learned that the datalookup function trigger only when there is a UI change on field or an Onchange is triggered by client script.



Now, I am trying trigger Onchange event on Risk field when ever the "Likely falure" and the "Failure Consequence" changes.



I can achieve by setting the same value to Risk field again. However, on of my colleague did mention that I can trigger an Onchange event but now he is on holiday. I am trying that approach but is not working


Hi Padmini,



Is the "Run on form change" checked on your defined Data lookup Definitions ?



find_real_file.png



Regards,


Suraj Chauhan


I did, but still it is not triggering an Onchange on form inorder trigger the 2nd datalookup rule