what is the purpose of having if(isLoading || newValue == ''){return} in on change client script??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 02:09 AM
I know if we want to write onload script in on change that we can write here but what was the purpose of this function mentioned here in every on change client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 02:15 AM
Hi
It means whenever u change value of that field it gets replaced by new value at time of changing value of that field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 02:23 AM
Hi @Manikantahere,
That condition basically means if the page is loading OR the new value of the field is empty, exit the script. Of course, you can modify it to meet your needs.
Refer to the documentation for the details - https://docs.servicenow.com/bundle/washingtondc-application-development/page/script/client-scripts/c...
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 02:24 AM - edited ‎02-28-2024 02:28 AM
Hi @Manikantahere
As you know onChange client script can also be run as an onLoad script if you comment out the return.
The answer to your question isLoading means if you want to run some code on onLoad then you can write inside it whereas newValue indicates if the selected variable has an empty value then what needs to perform.
Also, you can separate the functionality like
if(isLoading){
//perform anything on onLoad of the page
}
if(newValue== '' ){
//perform anything when the newValue is empty.
}
..then your onChange script will work from here
Please mark this as helpful and accept it as a solution if this answers your question.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 02:24 AM
When you're filling out a form online, sometimes the page is still loading when you start typing or changing something. That's like the isLoading part. The script checks if the page is still loading, and if it is, it waits until everything's ready before doing anything.Now, imagine you're typing something into a box, but then you decide to erase it and leave it empty. The script also checks if you've left the box empty. If you have, it decides not to do anything because there's nothing to work with.So, with if(isLoading || newValue == ''){return}, the script is basically saying, "Hey, if the page is still loading or if you've left the box empty, let's not do anything for now. We'll wait until everything's ready, or until you've actually typed something in."It's like the script is being patient and making sure everything is just right before it starts working.