The same piece of logic, e.g. cleaning up an email address, gets copied into yet another workflow. You change the rule and have to fix it everywhere. There is a better way: a sub-workflow.
Four things to get right:
- Sub-workflow: a regular workflow that starts with an Execute Workflow Trigger node. It does one thing and returns the result.
- Execute Workflow: a node in the main workflow that runs the sub-workflow. You choose which workflow to call and pass it data.
- Input data: in the sub-workflow's trigger you set Input data mode, e.g. Define using fields below. The workflow then receives only the fields it expects, not everything.
- Result: the output of the sub-workflow's last node comes back to the main workflow. You keep working with it as usual, e.g.
{{ $json.email }}.
Watch out for:
- Changing the input fields in a sub-workflow breaks every workflow that calls it. Give it a clear name and change it carefully.
- Run once for each item runs the sub-workflow separately for every item. With a large list that means many executions. If one call is enough, choose Run once with all items.
- An error in a sub-workflow usually stops the main workflow too. Handle it the way we did in episode 06.
Rule of thumb: when the same logic shows up a second time, move it into a sub-workflow.
Upcoming meetups and workshops are listed in the Events section.