- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 02:58 PM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 08:35 AM
Hi Brian,
please check below links it should help
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 08:35 AM
Hi Brian,
please check below links it should help
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 10:46 AM
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 08:15 AM
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