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

Hi , check the data type of the field. If it's a choice list check the value for the choice . Hopefully that should be the issue


ok alert sill not firing but it IS setting the fields to null and No



variable onChange: foo



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')


      g_form.setValue('foo' , '') //set field to null UI script hides foo when bar is No


   


 


      }



  }


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')



 



      }



  }


bbarber9
Giga Expert

Are either of the setValues changing the value of the variable that has the onChange script?


yes, thats the weird part its is setting the values.   I actually accidentally had the below (was changing it over from a field msg to an alert and was going too fast ) and it popped up u_field in the alert but got in an endless loop



alert('u_field','test','info');