Saltar al contenido

Lección 15 · Flow Control

Sub-workflows and Waiting

Reuse logic with n8n sub-workflows, design clear inputs and outputs, pause executions with the Wait node, and resume them by time, webhook call or approval.

As automations grow, two needs appear: reusing logic across workflows and pausing a run until something happens later. Sub-workflows solve the first. The Wait node solves the second.

Sub-workflows

A sub-workflow is a normal workflow called by another one. The caller uses the Execute Sub-workflow node. The called workflow starts with a trigger meant for being called by another workflow, which can define the inputs it expects.

flowchart LR
  A["Parent: new order"] --> B["Execute Sub-workflow: Notify team"]
  B --> C["Parent continues"]
  B -.-> S["Sub: format message, send"]
  S -.-> B

The parent hands data to the sub-workflow and, if it waits, receives its final output.

Use them to:

  • share steps such as "send alert" or "normalize address" across many workflows;
  • split a huge canvas into readable parts;
  • give one team ownership of one piece.

The node can run once with all items or once for each item. The option Wait for Sub-Workflow Completion decides whether the parent pauses until the child finishes. If you turn it off, do not expect the child's result. Since n8n 2.0, if the child resumes after waiting, the parent receives the child's final output. In 3.0, loading a sub-workflow from a local file or URL was removed.

Design an interface

Treat a sub-workflow like a function:

Question Example
What goes in? channel (text), message (text)
What comes out? sent (true or false), reference
What if it fails? Clear error message
Python Stand-in: a sub-workflow as a function with checks

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Version carefully. Changing a sub-workflow can break every parent that calls it, and a published version is what production runs use. Keep inputs backward compatible, or create a new version and move callers one at a time.

The Wait node

Wait pauses an execution and resumes it later. Depending on your settings, it resumes:

  • after a time interval, or at a specific date;
  • when a webhook call arrives;
  • when a person submits a form.

While waiting, the execution is saved, so it does not need to keep your editor open. With the webhook option, n8n creates a resume URL available as $execution.resumeUrl. Send that URL to the person or system that should continue the run, for example in an approval email:

TEXT
Approve the refund: {{ $execution.resumeUrl }}?decision=approve
Reject it:          {{ $execution.resumeUrl }}?decision=reject

Each execution gets its own URL. A partial test run can create a new URL, so share it in the same execution as the Wait node. Add a time limit so the workflow does not wait forever, and decide what happens on timeout.

Treat a resume URL like a password: anyone who has it may continue the run. Do not post it in public channels. If an action is important, also check who is approving, not only that the link was used.

Handling decisions

JS Stand-in: process an approval with a timeout

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Note the last case: an unexpected value does not approve anything. Default to the safe choice.

Common mistakes

  • Copying the same steps into five workflows instead of using one sub-workflow.
  • Turning off waiting and then expecting the child's data.
  • Building approval waits with no timeout or fallback.

Handling errors across workflows

A failure inside a sub-workflow can affect its caller, so decide how errors travel. If the parent waits, you can let the child fail and handle it in the parent with the node's error settings. Alternatively, the child can return a result such as { "ok": false, "reason": "invalid channel" } for expected problems, and reserve real failures for unexpected ones. Be consistent so every caller handles the same shape.

If the parent does not wait, it cannot react to the outcome, so give the child its own error workflow and logging. Test the child on its own with sample inputs before you connect it to any parent, including missing and badly typed values. Avoid long chains in which one workflow calls another that calls another. They are hard to trace, and a workflow that calls itself without a stop rule can loop until something breaks.

Long waits deserve a thought too: someone may answer days later. Check that the approval still makes sense when it arrives, for example that the order has not already been cancelled.

Practice

Design a reusable "request approval" sub-workflow. List its inputs, such as a title, details, approver and time limit, and its output, such as approved, rejected or timed_out, plus who decided and when. Write what happens if an input is missing. Then imagine two parents using it: one for refunds and one for publishing a post. Check that neither needs special cases inside the shared workflow. If one does, your interface may need another input, or the two processes may not be as alike as they first appear.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What is a good reason to create a sub-workflow?

    Shared logic is easier to maintain in one place.
  2. 2. What is $execution.resumeUrl used for?

    Calling the URL resumes the waiting execution.
  3. 3. What should an unexpected approval response do?

    Default to the safe outcome when input is unclear.

Summary

  • Sub-workflows package reusable steps with clear inputs and outputs.
  • Choose whether the parent waits for the result.
  • The Wait node pauses until time passes or an event arrives.
  • Protect resume URLs and add timeouts with safe defaults.

Next: Error Handling

Tu progreso se guarda en este navegador. No necesitas una cuenta.