Loop thought list collector

Brian Lancaster
Tera Sage

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.

11 REPLIES 11

Mark Stanger
Giga Sage

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]


}


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.


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.


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.