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.

On change variable reset lookup select box to ---None---

wayneryeo
Kilo Contributor

Hi,

I have a lookup select box and i want to reset it to element 0 of the select box or ---None---(which is the original value on load) when another selectbox value is changed.

Can anyone advise me what should i use?

I tried to set value or add option but none of it resets it to the default none value for the selectbox.

g_form.setValue('name',0);

g_form.addoption('name', "", '---None---', '0');

Thank you!

1 ACCEPTED SOLUTION

oharel
Kilo Sage

Hi Wayner,



I think it is much more simple:


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



For instance: an onChange script that changes priority to --none-- once the state field is changed:


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


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


          return;


  }



  //Type appropriate comment here, and begin script below


if(newValue)


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


}



harel



Edit:


If you want the value to be '0', then:


1. make sure that you have one of your options in the choice field with a value of 0


2. the line should be: g_form.setValue('name', '0'); //the 0 should be between ' '


View solution in original post

4 REPLIES 4

oharel
Kilo Sage

Hi Wayner,



I think it is much more simple:


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



For instance: an onChange script that changes priority to --none-- once the state field is changed:


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


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


          return;


  }



  //Type appropriate comment here, and begin script below


if(newValue)


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


}



harel



Edit:


If you want the value to be '0', then:


1. make sure that you have one of your options in the choice field with a value of 0


2. the line should be: g_form.setValue('name', '0'); //the 0 should be between ' '


wayneryeo
Kilo Contributor

Thanks alot Harel.



Your method works. i was trying to set it as element 0 but somehow it doesnt work.


Hi Wayner,


Do you need still help with the 0 thing?



harel


wayneryeo
Kilo Contributor

Hello Harel,



All good. i just needed to reset it to the default none.



Thanks.



Cheers.