Main workflow does not wait for all sub-workflows to complete and aggregate all the results

Describe the problem/error/question

We have a use-case where we Split-out list of objects in the main workflow and trigger sub-worflow for each item in the list.
Sub-worflow has Wait nodes defined which waits for user approvals to proceed further.

In this case, main workflow resumes once the any one sub-workflow completes. We are looking for a solution where main workflow waits for all the sub-workflows and provide us the combined results from all the sub-workflows

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

hello @shakthipsg

What is your n8n version?

Actually, the logic is not very good, as if the user misses Approving/Rejecting any of the items, the whole workflow won’t finish.

More reliable logic would be to not wait for the sub workflows at all. Instead, do the following:

  1. Save all item ids in the data table with columns like itemId, isApproved (do not fill it yet), parentExecId (the execution id of the main workflow, available by calling {{ $execution.id }}), then pass all items to the sub approving WF in the for-each mode
  2. In each sub WF approve/reject flow, wait for the corresponding action and set a timeout for waiting.
  3. When the approve/reject/timeout happens, update the DT entity for that itemId and call the final WF (or create a check if all items were processed and then call the final WF once all items are finished)
  4. In the final WF, check if all items of the parentExecId were processed (has either isApproved: false or true) and do the ending logic. Then remove the processed entries from the Data Table
1 Like

Hi @shakthipsg

Hope you are doing well.

To get a combined result from all items, you need to change the pattern.

Either remove the Wait nodes to keep everything synchronous, so the main workflow can truly wait for all sub-workflows to finish, or embrace the asynchronous model and have each sub-workflow write its result to an external store (database or table). Then use a separate consolidation workflow to read all those records and build the final aggregated result.

1 Like

Thank you @barn4k @tamy.santos
Yes, with external storage for the sub-workflows status works. Just want to check on any in-built support within the parent-child workflows.