How to loop a workflow based on on a list collector for the cmdb_ci_server table

Brian Kimani2
Tera Contributor

I am trying to loop through a number of blocks in a workflow. Basically the user will choose a number of servers from a list collector and the blocks should be executed once per server selected. 

I am using this code in my if block to loop through the list collector:

answer = ifScript();
function ifScript(){
var selectedCIs = current.variables.ci_name.toString();

var array = selectedCIs.split(',');

for (i=0; i<array.length;){
answer = true;
if(answer == true){
workflow.scratchpad.selectedCI = array[i];

return 'yes';
}
return 'no';
}
}

 

The result is an infinite loop that only considers the first item in the list collector. I have attached an image of the section I need to loop.

Any help or ideas on how to solve this?

1 ACCEPTED SOLUTION
7 REPLIES 7

@Brian Kimani 

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Brian Kimani2
Tera Contributor

Yes Currently I am making the if condition to evaluate again and I think every time it is trying to pick the CIs all over again. Yes I need it to pick the next CI every time it is evaluated. So if I choose 4 CIs from the list collector, the if condition gets evaluated only 4 times. I have no restrictions on what block to use, I just need to find a way to:

1. Store choices chosen from the list collector (CIs)

2. create catalog tasks for each of the CIs

3. Query some attributes of the CIs

4. Ability to store the gathered information