Client Scripts: onLoad vs. onChange

gauravchoudhury
Tera Guru

Currently I am new to ServiceNow and I trying to understand from a conceptual level on the significance and purpose behind various scripting. Apart from the usual text book definition of onLoad and onChange scripts, how would we different the significance, purpose or usage between these two scripts?

Regards,

Gaurav Choudhury.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Gaurav,



  • onLoad means the Client Script runs when the form or page is loaded
  • onChange means the Client Script runs when something specific gets changed AND also when the form or page loads

Additional parameter for onChange client script is : isLoading - identifies whether the form is loading and also indicates that no fields have changed value. This parameter can only be true when the form is loading and no values have changed.



http://wiki.servicenow.com/index.php?title=Client_Scripts


View solution in original post

5 REPLIES 5

Rohini Sane
Tera Contributor

Hi Gaurav,

OnLoad() - OnLoad client Scripts execute script logic when forms are loaded. 

For example -  Setting logged user in caller field. 

OnChange() - OnChange Client Scripts execute script logic when a particular field's value changes.

For example -  If the State field's value changes to Closed Complete, generate an alert.