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.

How to clear select lookup box variable value?

Lisa Goldman
Kilo Sage

Hello,

I have the following two variables, reference and lookup select box.  The variables are getting data from the same table: u_part_number

 

LisaGoldman_4-1709665567580.png

 

 

On the "lookup select box", I am using Auto-Populate to fill in the Part Id variable.

 

LisaGoldman_2-1709664805739.png

 

How to you clear Part Id variable on Part number changes.

LisaGoldman_5-1709665668584.png

 

 

Here is the onChange script I have tired, but it did not work.  Please help.  Thank you

 

LisaGoldman_3-1709665307797.png

 

 

 

 

1 ACCEPTED SOLUTION

@Lisa Goldman  Strange , but anyways you can give another try. 

 

Set 'Include none' as true on your Lookup select box variable and now use below script.

eg:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (newValue == '') {       
	 g_form.removeOption('part_id','');
        g_form.addOption('part_id', '', '');
    }
}

 

Thanks,

Harsh

View solution in original post

20 REPLIES 20

Sylvain12
Tera Contributor

Hello Lisa,

 

If you want to clear a value from onchange script, that use lookup select box type variable, add a condition with newValue == null:

 

 

    if (newValue == ''|| newValue == null) {
        g_form.clearValue('variable_name');
    }