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.

OnChange script on reference field

uma17
Tera Guru

Hi All,

I have an onchange() script on the reference field , which works fine when I change the value of the field, but when I make the field blank by erasing the value, the onChange script wont get called.

So the check if(newValue == "") never gets called.

Thanks,

Uma

1 ACCEPTED SOLUTION

Because it is returning out of the script.   Take out the



|| newValue == ''



and it should work fine.


View solution in original post

7 REPLIES 7

Mike Allen
Mega Sage

Can you post your script?



We were able to get it done just using:



if (newValue == '') {


  g_form.setValue('configuration_item' , '');


}


David OBrien
Kilo Guru

Could you post your script where this isn't working?   Changing the value of a reference field to blank should trigger the if(newValue=='') condition.   Just tested it out to make sure and it's working in a demo instance.


Hi David,



It works fine, when the below code is not present, adding an alert after this line, is not working when I blank out the field.



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


          return;


    }


Because it is returning out of the script.   Take out the



|| newValue == ''



and it should work fine.