What is "isLoading" in client script?

PhoenixMing0912
Giga Expert

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?

8 REPLIES 8

So, does this means that both onLoad & onChange script runs one after another in the time of Loading the form to user. Apart from the fact, that, onChange even runs when a field is changed.

Hi Yash

I would Like to add my views here.

answer to your Question is

onLoad will always work as soon as form loads.

onChange will work only if the fields changes for which you have written script.

client scripts runs on users browser:-

If you have written a onLoad Client Script it will run as soon as form gets fully loaded to you after buffering. It is not a field dependent script.

Your onChange will work only when there is change in the field which you have entered in field section.

check the below screenshot.

onLoad:-Every Time Your Form Loads, it will definitely work.

find_real_file.png

find_real_file.png

Now we will try with onChange. with state field.

If there is change in your state then and then you will see the alert on the screen. otherwise it will not show you alert.

find_real_file.png

find_real_file.png

find_real_file.png

find_real_file.png

Now we will check this with another fields.

I will change the impact and urgency.

we will not get the alert as the changes are on another field.

find_real_file.png

Now one More Topic:-

I would like to tell you that,

Your This onChange Client script can work as onLoad.

That means as soon as your form Loads it will give you alert.

Just Remove the isLoading || from the script.

find_real_file.png

check you will see alert as soon as form loads. rather than change in the Field.

find_real_file.png

I Hope, You are clear Now

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat 

Yash Khanka
Giga Contributor

Hi Gaurav,

Even i was referring to this isLoading part, isn't it that way, that, since any thing that we have to make run on and as onLoad in a onChange we make it under this if condition ( or do it the way you did) but we are unable to see the result as by default it returns null (but checks the condition on the time of load i.e when onLoad runs). 

This particular if statement check and return makes me wonder if both the scripts run when a NewRecord is initiated.

PS: - if you try to add a change value statement between two alerts, both the alerts willl popup first, then the field value will be changed.

isLoading - it works at the time of form loading or we can say that when form opens it takes 2 seconds to 3 seconds loads all the contains properly so, at this time of loading if any changes happens at that field in which onchange client script is written it neglect that changes or it didn't consider that changes.
  • isLoading: boolean value indicating whether the change is occurring as part of a form load. Value is true if change is due to a form load. When forms load, all the field values on the form change as the record is loaded into the form.

https://developer.servicenow.com/dev.do#!/learn/learning-plans/paris/new_to_servicenow/app_store_lea...

Please let me know whether I have given you required answer or not?

else describe the your case here in some different way, so that I can resolve your query.

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat