- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 06:21 AM
It is a recommended practice to have "if (isLoading) return;" as the first statement of the onChange functions. It was suggested to me that there may be exceptions to that rule, but nothing specific was identified. What should I consider before I update 334 of our catalog client scripts? Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 06:24 AM
Hi Eileen,
Client scripts by default run both on onload and onchange, now if you dont want youer client script to work onload of the catalog item then u can write if(isLoading) return; but if the behaviour demands to be checked onload and onchange both then you cannot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 06:24 AM
Hi Eileen,
Client scripts by default run both on onload and onchange, now if you dont want youer client script to work onload of the catalog item then u can write if(isLoading) return; but if the behaviour demands to be checked onload and onchange both then you cannot.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 06:26 AM
If that is added in a onchange client script, it will not get executed on load. It depends whether you want your onchange client script to run on load of the form or not

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 06:28 AM
If you include that code, the client script only runs onchange. If it is not there, it will run both when the form loads and the field values change. It works this way because all of the forms are blank and then populated with data when the form loads, so all of the fields are technically changing.
All of that being said, if all of your client scripts are currently working how you want them to I wouldn't update them. The best practice would be to include this statement and not run the onchange on load if you don't have to in order to cut down on load time.
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 07:10 AM
Thank you all! I understand that I need to read each script to determine if it needs to be run onLoad. If so, I do not insert the 'isLoading Return' script. Brad, your answer was extra clear...thanks!