Onchange client script to onload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 01:28 PM
Hi,
Example:
function onChange(control, oldValue, newValue, isLoading) {
if ( isLoading || newValue == '') {
//If i write code here then it will execute on form load
return;
}
//If i write code here it will execute at onchange of field
}
My question is why should we remove "isLoading" to work onchange client script as onload client script?
Can someone help me with this
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 05:04 PM - edited 03-11-2023 05:05 PM
Hi,
No one is saying you "should" remove isLoading, but sometimes you may need to.
Some will choose to remove the isLoading to make the client script work onLoad if they don't want to write two separate client scripts (if they have both an onLoad and onChange piece).
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 12:00 AM
Hello @Allen Andreas ,
Let me reframe my query
When we can write onload and onchange without removing of "isLoading"
Then in which scenario we are removing isLoading to make onchange client script to work as onload. because this functionality is anyway we are achieving without removing of isLoading as well

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 08:35 AM - edited 03-12-2023 08:35 AM
Hi @anvitha ash
I believe you're asking for a scenario?
One could be where you want to hide or show values in a select-box/choice field and you want some of your script to do it onLoad and some onChange. You can definitely search the forums as well for other scenarios.
Technically all client scripts trigger onLoad, but onChange scripts that still have isLoading is them, just exit right away and do nothing. As mentioned above, there could be a situation where you want to have it execute onLoad because you've already written a bunch of script in there and don't want to create separate client scripts.
It's not really leading practice to do that and on a ServiceNow HealthScan check, I believe onChange client scripts that are missing isLoading are flagged that they need to be fixed. So...technically, you can remove isLoading in an onChange, but it's not leading practice to do it.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 12:12 AM
isLoading check is available in onChange script, in order to provide an opportunity to handle change in values of the fields when the form load.
When the form loads changes in field value are possible on the fly(during loading) because of any other field/ script etc.
So, in that case mostly we don't want our on change script to work because value is changed but not by any user, as we wanted.
So, to avoid all such background changes on the field we are asking system that "if the form is loading and there is a change in value of field , Please ignore it."