The Zurich release has arrived! Interested in new features and functionalities? Click here for more

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?

3 REPLIES 3

palanikumar
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
Kilo 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.