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

For better performance may help specialized addQuery() operator: "IN"

var GR = new GlideRecord('my_table');

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

GR.addQuery('sys_id', 'IN', myList );
GR.query();

while (GR.next()) {
    // Do what you want to the retrieved record
    GR.update();
}

 

Querying tables in script

addQuery(String name, String operator, Object value)

Hello Chuck, 

I have List Collector in catalog item, I am trying get the value of this using g_form.getValue() but it is not working.

 

 

rajeevhanda
Kilo Expert

You can also use the following way: 

var options = $j('#delegate_roles_roles_select_0 option');

var values = $j.map(options ,function(option) {
    return option.text;
});
console.log(values);

jbruns2019
Giga Contributor

Chuck,

If you are still around, is my_table literally what you meant to specify or is that a placeholder for something else?

What converts the selected values sys_id's to a real human readable value?

sys_ids are converted to readable values based on the table they are referencing. One field is designated as the display value (e.g. sys_user.name or task.number). With a list field, you must do a (GlideRecord) lookup yourself if you want to display the display values for the referenced records. Fairly easy on a server script, a bit more work on a client script.