Using a list collector in a catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2011 10:34 AM
I've set up a list collector variable for the table sys_user_group; the catalog item will ask the user to pick groups that we have already defined in our instance. My question is what can I do with the data that is placed in this variable?
I created a RITM record with this variable and then I run this code through Background - script. (The plan is to use a Run Script in the workflow, but I haven't built the workflow yet.)
var recList = new GlideRecord('sc_req_item'); recList.get('sys_id', 'e4bf6bf21c9a50009b1260927b40f723'); //This is the sys_id of the record I created var str = recList.variables.list; //The list collector variable gs.log(str);
When I run this code, the system will print out: b872401c0a0a3cde018c829760e8f69a,b8724c640a0a3cde012f44d3fcd6aa54,d60ffcfb0a0a3cde018716cd5204aaf6 (These are the sys_ids of the groups chosen in the record.)
The problem that I'm having is that I cannot manipulate the variable data in anyway. I've tried to treat it like a String, but none of the normal String attributes work. I cannot get the length or use any methods such as .slice() or .indexOf(); when I try to get the length or return the results of a method, the system outputs "undefined". I've also tried to treat it like an Array, but if I try and reference str[0] I get "undefined" as well.
This is my first attempt to use a list collector and I checked the Wiki but I didn't find much information on this topic. Any thoughts or assistance on this topic would be extremely helpful.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2011 01:21 PM
You can output the values from the list collector to an array and work with them from there by doing:
var str = recList.variables.list.toString();
var array = str.split(",");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2011 01:46 PM
Awesome! Thanks Brad! That's exactly what I needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2012 07:55 AM
Do you know if you can output the values from a List Collector in a Workflow?
Thanks!
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2012 11:34 AM
I didn't use this script in a workflow because we went in a different direction, but I don't see why this script wouldn't work in a "Run Script" workflow module.