Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

to restrict onchange client script to work when form loads

tanz
Tera Expert

i have a catalog form with field x - which has some onload client script which sets the value to xyz. Now i want to run an onchange client which should throw an alert if any other value is entered other then xyz. so next time when i change the variable it should throw that alert not during the time form loads. Now it is throwing the alert the first time only when form loads

2 REPLIES 2

ShubhamGarg
Kilo Sage

Hello @tanz ,

Does your catalog client script contain below line of code before your onChange logic?

 

if (isLoading || newValue == '') {
      return;
}

 

 Hope it helps.

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

Brad Bowman
Kilo Patron
Kilo Patron

Here's the pseudocode for the answer I provided to your same question yesterday

onLoad Catalog Client Script - you must/should be doing something like this already:

1. call a Script Include via GlideAjax, passing a value from the client/form if necessary.
2. in the callback function, set the value of the variable to the answer received from the server.

onChange Catalog Client Script:

1. call the same Script Include via GlideAjax, passing a value from the client/form if necessary.
2. in the callback function, if the answer received from the server is not the same as the newValue, then alert..