Is it possible to use OnChange client script at Onload?

Arishmit
Tera Contributor

I have a requirement and I want to execute a OnChange client script when the form loads. Is this possible? Any help would be much appreciated. 

1 ACCEPTED SOLUTION

Yes Buddy, It is possible to use OnChange Client script at OnLoad.

amitshishod_0-1738042726716.png

 


I am assuming that the task(For Onload and Onchange) is same, then you simply remove isLoading from line 2 and it will work same for load and change.

Please mark my response correct and helpful, if it helps you.
Please reply if any issue happens.

View solution in original post

7 REPLIES 7

Juhi Poddar
Kilo Patron

Hello @Arishmit 

  • Yes, you can use the same onChange client script to trigger when the form loads.
  • This can be achieved by simply removing the isLoading check from the onChange client script.

Syntax for Onchange change client script to execute when form loads:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (newValue === '') {
      return;
   }
// Type your script here

}

 

Note: Removing the isLoading condition ensures that the script runs even when the form loads.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

Harish Bainsla
Kilo Patron
Kilo Patron

Hi @Arishmit  check below link 

 

https://www.servicenow.com/community/developer-forum/can-we-change-onchange-client-script-into-onloa...

 

if my answer helps you mark helpful and accept solution

Ayushi12
Mega Sage

Hi @Arishmit
We can execute a OnChange client script when the form loads by removing the isLoading from the onChange client script.
isLoading - it works at the time of form loading, 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.

Ayushi12_0-1738044038877.png

 

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

Thanks!