Repeat Flow Based on Variable Answer

DylanB
Tera Guru

I have a catalog item that when closed, creates a CI. This works off a Flow. In the catalog item, there is a variable of 1-5 named "Number of Accounts". 

 

There was an ask to create a number of SCTASKs based on the answer to the Number of Accounts variable. For example, if the answer to the variable is 3, it creates 3 SCTASKs, and each SCTASK follows the rest of the Flow, creating a unique CI when closed. 

 

I'm struggling to find a good way to loop the flow until the correct number of SCTASKs is created. Does anyone have a suggestion on the best way to do this?

1 ACCEPTED SOLUTION

Alex Tod1
Kilo Sage
3 REPLIES 3

Alex Tod1
Kilo Sage

Hi @DylanB,

 This article might help you: https://www.servicenow.com/community/developer-forum/flow-designer-do-the-following-until-loop-limit...

 I did something similar based on counter.

 

 

Hi Alex, thanks for the reply. I tried something similar on my PDI, but I'm having trouble getting it to increment the flow variable. I have the following steps set up. 

DylanB_0-1694007968168.png


On step 5, I scripted incrementing the flow variable with the following code. I'm not well versed in scripting so I'm not sure if this is the correct code. I found it on another post and changed the variable name. 

DylanB_1-1694008056263.png

 

In testing, the flow is getting stuck waiting on step 3 and 4. The first SCTASK is being created though. 

DylanB_2-1694008125521.png

 

I figured out my issue now. The Create Catalog Task step had the Wait checkbox checked.

DylanB_3-1694008623313.png

 

I unchecked that and it it ran through the rest of the flow correctly, except that it would create one less ticket than the catalog item variable choice. To fix that, I set the flow variable to 0 in step 2 and it worked correctly.