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

yea yea i just didnt paste that


when you alert new value before the if statement what value is shown?


Abhinay Erra
Giga Sage

Just remove that foo line and try. You are still changing the foo value from No to ''



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


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


          return;


    }




    //if foo is no set bar to No and hide foo


 


      if(newValue == 'No'){


      alert(getMessage('this is my alert'));


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



   


 


      }



  }


now its not even changing the value of bar


Last try. Go to the catalog item form, fill in the variable foo with No. The press cntrl+shift+alt+j, this will open a JavaScript Executor window and copy this script in there and run the script and see if it works



find_real_file.png