Loop thought list collector

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2015 09:56 AM
I have a name change process where users select which application they use in a list collector where we have to manually update their username. How can I loop thought the list collector so that I can create a separate task for each item selected in the list collector.
- Labels:
-
Service Catalog
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2015 10:40 AM
List collectors just store a comma-separated string of sys_id values. You can use a standard javascript 'split' to create an array of those values that you can loop through and perform an action against each one...
var myString = current.variable_pool.YOUR_LIST_COLLECTOR_VAR_NAME;
var mySplitResult = myString.split(" ");
for(i = 0; i < mySplitResult.length; i++){
var myGR = new GlideRecord(YOURTABLENAME);
//Continue here. Access the current item in the array like this...
mySplitResult[i]
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2015 10:13 AM
So am I doing this in the catalog task advanced section? As some of what is picked in my list will send out notification instead of creating tasks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2015 04:26 PM
You could do it in any number of places. The only thing that changes is that 'current' needs to be adjusted to point to the catalog item record and then everything flows from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2015 10:34 AM
Hey Mark,
I am trying your loop within a workflow and I can't split anything in this list output. I definitely can see the values but I can't apply a split or get the length of the defined array at all. Trying to just do a Run Script activity to loop through the list.
I have a list of sys ids.
var myString = current.variable_pool.access_list;
var mySplitString = myString.split(",");
var myLen = mySplitString.length;
gs.log(myString); = I see my list value from my variable comma separated
gs.log(mySplitString); = undefined
gs.log(myLen); = undefined
Is there a reason why I can't get array info?
Thanks.