How to clear the contents of a glide list using a client script

chadlockwood
Kilo Sage

I have a checkbox and a list collector(glide_list) on a catalog item. if the checkbox is checked(true), the glide_list is visible(via UI policy). If the requestor adds items to the glide_list but then unchecks the checkbox, I want to clear the contents of the glide_list.

In the JavaScript Executor, I have run the following:

var a = g_form.getValue('IO:81332e394f2ae200b8ec7f75f110c77e');

alert(a);

var b = [];

g_form.setValue('IO:81332e394f2ae200b8ec7f75f110c77e', b);

Lines 1&2 successfully collect the contents of the glide_list and display them as a comma-separated list of sys_ids, as expected. Lines 3&4 appear to successfully set the value of the field to an empty string, however, the display values remain in the field. If I run lines 1&2 again, the alert appears to return nothing.

Additionally, I have an onSubmit client script that shows an error message if the checkbox is checked and the glide_list is empty. If I run the above code and click Submit, the error message appears, as if the glide_list is empty, even though the display values remain.

Is there another way to clear the contents of a glide_list using a client script? Or do I need to find some way to re-render the glide_list after I've cleared it out?

1 ACCEPTED SOLUTION

Patrick,


Here is what I did:


First, open your catalog item, right-click the window portion that holds the items you select, then click Inspect.(assuming you are using Chrome)


Look for the "name" attribute, should look something like:


name="select_0IO:81332e394f2ae200b8ec7f75f110c77e"


Copy the value of the name attribute, including "select_".


Add this code to your script to clear the values:



g_form.clearValue('<variable_name>');


g_form.clearOptions('select_0IO:71332c394e2ae212b8ec6f65f110c66e');//replace with your "select_" value



I believe the system technically recognizes the glide_list as two separate fields which is why both lines are necessary.



Hope this helps.


View solution in original post

17 REPLIES 17

Abhinay Erra
Giga Sage

This is a slush bucket variable right?


It is a list collector(slushbucket) with the glide_list attribute.


Abhinay Erra
Giga Sage

Can you post a screenshot of how the variable looks?


Dave Aiken
ServiceNow Employee
ServiceNow Employee

Try the link below.   I think it may be what you're looking for.


Clearing a list collector