Getting selected values in a list collector catalog variable

rhofing
Tera Contributor

One of the variables in my catalog item is a list collector. This list collector permits users to select records (move from left to right) to be de-activated.   Upon submit (I will use a On Submit client script), I want to loop through the selected value(s) in the list (right-side of the list); then I will find the appropriate record in the table and set Active = false.   I know how to update the record (GlideRecord), and how to code a loop, but I am not certain how I get the Selected values into an arry.   Thanks!

Ric

19 REPLIES 19

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hey Ric,



You may find below thread helpful.


Get DisplayValue of selected items in List Collector


Chuck Tomasi
Tera Patron

Hi Ric,



The values of the list variable are stored in a comma separated list of sys_ids. To get that in to an array, you only need to split(). Something like this



var myList = g_form.getValue('my_variable');


var myArray = myList.split(',');



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


        var gr = new GlideRecord('my_table');


        if (gr.get(myArray[i])) {


                  // Do what you want to the retrieved record


        }


}



Hope that helps.


I tried both methods and both worked perfectly!   Thank you very much.



Ric


Thanks Ric for the update.


Would you mind marking answer as correct and close the loop.




P.S. Some users do not see the Correct Answer link (per this video at 20:00 https://community.servicenow.com/thread/224893). Let me know if you do not see it and I can get a community moderation to assist.