What is "isLoading" in client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 07:41 PM
Hi all,
In client script there is a predefined flag "isLoading", I am wondering when it should be used.
I think almost client scripts are executed after the UI was rendered, I am wondering if someone could give an example of something can be done in the middle of loading?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 08:13 PM
onChange client scripts run whenever a value on the g_form changes. This includes when the page loads and ServiceNow set the initial values of the fields. isLoading is used so you can know when the change is one made initially by the system vs one made after all the fields have been given their first value.
Normally you will set onChange client script to run something when the user makes a change so you don't need them to run when the values are first set (you can use onLoad for this) so you have the isLoading check to only run it in that case. There are cases where you want something to run on both onLoad and onChange. In this case you can remove the isLoading check at the beginning of a script and it will run on both so you do not have to make two duplicate client scripts for onChange and onLoad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 08:53 PM
isLoading can be a good check if you only want to trigger scripts after the initial loading.- Since an OnChange Client script can run onChange and onLoad, using isLoading will prevent it from running onLoad.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 09:16 PM
Hello
isLoading: boolean value indicating whether the change is occurring as part of a form load.When forms load, all the field values on the form change as the record is loaded into the form
onLoad() Scripts
An onLoad() script runs when a form is first drawn and before control is given to the user to begin typing. Typically, you use an onLoad() script to perform some client side manipulation of the document on screen.
An onLoad() script must contain a function named onLoad(). Otherwise, it is entirely up to you what your script does after it gets to the client.
function onLoad() { alert ('Loading ...'); }
Even One more Interesting Thing I want to tell you,
Your onChange() Client Script can Potentially work as onLoad():-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
}
if you Remove this "isLoading||" your onChange Client Script will work as a onLoad
refer this for more details.
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 10:01 PM
Hi,
In addition to above, The purpose of isLoading is simple.
If you have onChange client script for field and in same client script if you want to perform some operation at the time of form load then we use that isLoading.
Below example will clear your doubt.
Create onChange client script on any field and paste below code in script section, And check the functionality. You will understance.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading ) {
alert("at the time of form loading");
return;
}
alert("at the time of field changing");
}
Thanks,
Dhananjay.