How to reset/clear dropdown component in UI Builder using client script?

raajesh
ServiceNow Employee
ServiceNow Employee

Hi,

 

I working on the UI builder and I want to reset the dropdown component from selected value to the default unselected.

 

How to achieve that resetting dropdown or clear using client script?  

Thanks in advance.

 

6 REPLIES 6

JagjeetSingh
Kilo Sage
Kilo Sage

Hi,

 

This is how you can do it.

1. Create a state parameter. For example- "selectedItems" of JSON type and set the value to [].

2. Bind the "Selected Items" property of your dropdown component to this state parameter.

JagjeetSingh3_0-1674285603217.png

 

3. Create a client script to set the state parameter.

JagjeetSingh3_1-1674285656264.png

 

4. Trigger your client script from any event and the value would reset. Thats it!

 

 

 

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023

raajesh
ServiceNow Employee
ServiceNow Employee

Hi @JagjeetSingh ,

 

Using setState does not resetting the dropdown component, the selected items remains display. I need to clear the selected items in dropdown. 

Is there any way to emit event to clear selected items? or any other options will helpful.

 

Thanks in advance.

did you follow each step. I did this in my PDI and it works.

Make sure your state parameter is of JSON type and you have to bind it with the component properties.

 

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023

raajesh
ServiceNow Employee
ServiceNow Employee

I have followed all steps as you mentioned and using state variable as JSON.

But not able to clear selected items in the dropdown, component keep showing the selected items.

ui buidler dropdown.png