Wait for last task within a Subflow that runs within a For Each to Complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2025 12:09 PM
Hi,
I have a Subflow that is setup within a For Each Container that has all multiple tasks based on condiiton. I want to wait for all the tasks withing the subflow to complete to proceed. I cannot use Wait for Subflow execution as it's in a For Each & enabling it will block next task unti the first task is complete.
I have tried 'Do until' running outside the 'For Each' which fails due to maximum execution exceeded. I tried to lookup the Subflow execution to complete with a Looku & Wait for condition for it to complete which is visible but shows Empty when saved.
Any advise how do we wait for all these tasks to be Closed before it comes here. Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 06:35 AM
Hello @iDNS,
-
1. Initialize a Counter:Create a flow variable (e.g.,
task_counter
) and initialize it to 0. This will track the number of completed tasks. -
2. "Do Until" Loop:Place a "Do Until" loop outside the For Each container.
-
3. Inside the "Do Until" Loop:
- Increment Counter: Inside the loop, increment the
task_counter
variable by 1 in each iteration. - Check Task Completion: Use a "Look Up Records" action to find all the tasks within the current iteration of the For Each loop (based on the For Each's iteration value and any relevant conditions).
- State Check: For each task found, check its state. If all tasks are in a "closed" state (or your desired completion state), set a flag (e.g.,
all_tasks_completed
to true). - Break Condition: If the
all_tasks_completed
flag is true, use a "Set Flow Variables" action to set the loop's exit condition (e.g., setDo Until
loop's condition totrue
).
- Increment Counter: Inside the loop, increment the
-
4. Loop Exit:The "Do Until" loop will continue until the exit condition is met (i.e., all tasks are closed).
-
5. Continue:After the "Do Until" loop, the flow can safely proceed to the next task, knowing that all subflow tasks have completed.
graph LR
A[Start] --> B(For Each Container);
B --> C{Subflow Tasks (e.g., Create Catalog Task)};
C -- Iteration --> D{Look Up Records (Tasks)};
D -- Check State --> E{All tasks closed?};
E -- Yes --> F{Set Flow Variable: all_tasks_completed = true};
F --> G(Do Until Loop Exit Condition);
E -- No --> H(Increment task_counter);
H --> C;
G -- Exit --> I(Continue);
I --> J(End);
Do Until
), and the continuation point after all tasks are closed. - Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 10:42 AM
I've already tried that, but it doesn’t work as expected. The issue is that the Subflow uses a Wait for Condition step to generate additional tasks. However, these tasks aren’t accounted for because the system moves on to the Do Until loop before those additional tasks—triggered by the wait condition—are created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 11:40 AM
Hi @iDNS ,
To wait for all tasks created in a subflow to complete, you can either return a list of task sys_ids from the subflow or use a shared identifier like a parent record or some filter. In the main flow, use a Lookup Records action to fetch all tasks—either by filtering on the returned sys_ids or by using the shared identifier (e.g., Parent = current.sys_id). This gives you a list of all tasks created during the subflow execution.
Next, use a For Each loop on the lookup results and add a Wait for Condition inside the loop. This condition should check that each task’s state is “Closed” (or your desired completion state). This setup ensures the flow waits for each task to finish before continuing, without using scripts or hitting execution limits.
Please mark this as helpful and correct if this helps.
Thanks,
Yaswanth.