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

Hey @Lisa Goldman,

 

Is the 'u_part_number.part_id' a reference type or a string?

 

Cheers

@James Chun ,

It was on lookup select box type.  I changed to reference type to make it works.

LisaGoldman_0-1709672463663.png

 

No, I meant the Part id field on the part number [u_part_number] table. The one you are referencing to fetch the data.

@James Chun 

Sorry James! 

Here is the table attributes:

LisaGoldman_0-1709673974781.png

 

 

Thanks, since the field is a 'String' type, you should also use a string type variable. Once you change the variable type, you can deactivate the Client Script.

Just a tip, make sure these data types are aligned, otherwise you will see unexpected behaviors.

 

Cheers