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.

Alert not firing on onChange client script

sigmachiuta
Kilo Guru

i have a onChange catalog client script that DOES change the field values so it is running but it doesn't throw the alert.

if(newValue == 'No'){

      alert(getMessage('test'));

      g_form.setValue('foo' , 'No')

      g_form.setValue('bar' , 'No')

   

      }

--or

if(newValue == 'No'){

      alert('test');

      g_form.setValue('foo' , 'No')

      g_form.setValue('bar' , 'No')

   

      }

1 ACCEPTED SOLUTION

clear cache and check to clear form data and that should resolve that part of it.


View solution in original post

39 REPLIES 39

If you are setting the value of a variable that has an onChange script, it will cause an endless loop unless you have some sort of check. It is not recommended to change the value of a field in its own onChange script.


i am setting the value of the field in this on change script


randrews
Tera Guru

try adding an alert before the if statement... this will show you if it is an issue with newvalue or with the if statement.   however... as the other person stated.. you shouldn't change a value in an onchange script for itself.... that causes a loop.




alert('new value is ' + newvalue);


No alert new value when alerting before if..... freaking weird


randrews
Tera Guru

also if that is your entire script you are missing the function calls to allow newValue.... your script should be wrapped inside the function below... you can skip the if for newValue == '' and isLoading if those aren't desired.. <i need some onchanges to run onload also.






function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }



    //Type appropriate comment here, and begin script below


   


}