Can i run an on change client script run on load client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 11:40 AM
Hi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 11:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 11:46 AM
Yes
in your onLoad, do this
function onload {
runMyScript();
}
function runMyScript()
{
alert('boo');
}
runMyScript can be called by any other

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 11:47 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 11:47 AM
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