Can i run an on change client script run on load client script

n_nagireddy
Kilo Explorer

Hi

4 REPLIES 4

Chuck Tomasi
Tera Patron

If I understand, you want to run an onChange client script when the form loads. By default, they do. There is a little code added to the template using the isLoading flag to normally tell the script NOT to run when the form is loading. If you remove that, it will work.



Default:



if (isLoading || newValue == '')



Change it to



if (newValue == '')



It will run when the form is loading.



Client Scripts - ServiceNow Wiki


poyntzj
Kilo Sage

Yes


in your onLoad, do this



function onload {


        runMyScript();


}



function runMyScript()


{


alert('boo');


}



runMyScript can be called by any other


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Sravani,



OOTB the below script prevent an onChange() script from running when the form loads


if (isLoading) {


  return;


}



You need to remove this line to make it work OnLoad.


Atul Kumar2
Giga Guru

Hi Sravani,



No, you can not use this. since once form is loaded at that time it renders the value from back-end to the user interface and it does not change the value on the form whereas


on change client script will be used when you are changing any value from one state to another(work in progress to resolved or editing short description field etc ) then on   this , change event will be fire in backend and corresponding logic will be executed.



Hope this make sense.



Regards,


Atul Kumar