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

Hi Patrick,



did you finally get a way to set the glide_list value ? I'm stuck on the same.



Thanks



Agathe


Yes see glide_list operation from client Script or ask me if you need


Regards


Patrick-


I am also stuck on this for glide_lists



using the below code i was able to get my options to populate correctly returning from a glideAjax call UNTIL my onchange fired again (the user selected a different choice) So looking at your post I added the clear options you see in the second code snip.   The weird part is that after adding the clear options I am only returning the last value in the string to the glide_list when the onChange fires.   I am still returning all values in my xml response it is very unusual any thoughts?



var answer = response.responseXML.documentElement.getAttribute("answer");


var actionArray = answer.split(',');


for(i=0;i<actionArray.length;i++){


var ref = g_form.resolveNameMap('db_role');


$(ref + '_unlock').click();


addGlideListChoice('select_0' + ref,   actionArray[i], actionArray[i]);


$(ref + '_lock').click();


}




var ref = g_form.resolveNameMap('db_role');


$(ref + '_unlock').click();


  g_form.clearValue('db_role');



  g_form.clearOptions('select_0IO:ba8c351fdb31f200ae7efdb61d96190c');


  $(ref + '_lock').click();



$(ref + '_unlock').click();


  addGlideListChoice('select_0' + ref,   actionArray[i], actionArray[i]);


  $(ref + '_lock').click();