The CreatorCon Call for Content is officially open! Get started here.

Turnstile / loop counter in a subflow?

ILYA STEIN
Tera Guru

I am designing a subflow that needs to perform up to a specified number of checks for a condition. Looking for an approach that will be equivalent to a workflow turnstile, or a counter to use in the loop. Any recommendations?

1 ACCEPTED SOLUTION

kaushal_snow
Mega Sage

Hi @ILYA STEIN ,

 

You can build a turnstile / loop counter in a subflow by giving it an integer input like max_attempts, initializing a flow variable counter to zero, using a Do Until loop that checks counter < max_attempts (or until your condition is met), incrementing the counter each pass, and then outputting whether the condition ever succeeded along with how many attempts were used...

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

View solution in original post

5 REPLIES 5

palanikumar
Giga Sage
Giga Sage

There is no direct option available. You can follow the below steps:

1) Create a flow variable with name iteration_count

2) Create a Do Until loop with condition iteration_count is less than the number of iterations

3) Within the loop add your code

4) at the end of look before the condition step add a step to set the flow variable

5) Update the Inline Script of Data as below

     var data = fd_data.flow_var.iteration_count + 1;
     return data;

palanikumar_0-1758215610363.png

Note: Use Iteration Count instead of Position in the above screen shot

 

Thank you,
Palani

Sarthak Kashyap
Tera Expert

Hi @ILYA STEIN ,

 

You can use the flow logic as - Do the following until or For Each loop

1. Do the following until

SarthakKashyap_0-1758216875952.png

2. For Each 

SarthakKashyap_1-1758216920855.png

 

Please mark my answer correct and helpful if this works for you

Thanks,

Sarthak

aruncr0122
Mega Guru

Hi @ILYA STEIN , 

you can try below approaches :

 

🔹Approach 1: Use a Counter Data Pill in the Subflow

Add an Integer input to your subflow, e.g., max_attempts.

Initialize a local counter (data pill → Integer, start at 0).

Inside the subflow:

Add an If condition:

If counter < max_attempts → perform check.

Else → exit the subflow.

After performing the check, increment the counter by 1.

If the condition still isn’t satisfied, call the same subflow again (recursive approach).

This gives you a turnstile-like loop.

🔹Approach 2: Use a "For Each / Repeat" Loop Action

Flow Designer has a "Do Until" pattern by using "For Each Item" with a generated list.

You can generate a list of numbers from 1 → max_attempts (via Script step).

Then in the loop body, perform the check and use “Break” action (subflow return) when condition is met.


🔹Approach 3: Use Script Step for Counter Logic

If you’re okay embedding some script:

Add a Script step with something like:

var attempts = 0;
var max = fd_data.max_attempts; // from subflow input
var success = false;

while (attempts < max) {
attempts++;
if (/* your check condition */) {
success = true;
break;
}
}

fd_data.success = success;
fd_data.attempts_used = attempts;


Return success/failure and attempts count as outputs.

This is closest to the old workflow “turnstile” activity and very efficient.

kaushal_snow
Mega Sage

Hi @ILYA STEIN ,

 

You can build a turnstile / loop counter in a subflow by giving it an integer input like max_attempts, initializing a flow variable counter to zero, using a Do Until loop that checks counter < max_attempts (or until your condition is met), incrementing the counter each pass, and then outputting whether the condition ever succeeded along with how many attempts were used...

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/