Sunday, June 15, 2025

Tip #1: Testing n8n sub-workflow

Sometimes you need to move a set of nodes to a separate sub-workflow in n8n and execute it by the main workflow. It allows to make your workflow more compact and also reuse it's part in other workflows. But how to test it properly without executing it by the main workflow?

So let's start with some simple sub-workflow. Of course the first node will be Execute Sub-workflow Trigger node:

Starting new n8n sub-workflow

Let's add some input field:

Adding input field to n8n sub-workflow

Now let's add Manual Trigger node which will be used for testing purposes:

Adding manual trigger node for testing n8n sub-workflow

Next we should do the trick - add two Edit Fields (Set) nodes, one is for test input and the other one will combine the input from both triggers:

Adding two set nodes to combine test and main workflow input

Specify color field with some test value in Test Input node:

Adding field for testing in n8n sub-workflow

And include all the input fields in Combine Input node:

Allowing all the input fields in set node of n8n sub-workflow

Let's try to execute this n8n sub-workflow:

Executing n8n sub-workflow to test

And check the input of the last node:

Checking the input of the last node of n8n sub-workflow after executing test

So you can see the same color field value we specified in Test Input node as Combine Input node output. If we execute this sub-workflow by the main n8n workflow with some color input it will be available in Combine Input node output as well.

Regardless the way we trigger our sub-workflow (manually or by main workflow) Combine Input node will always have color field value (testing value or real input from the main n8n workflow).

In further nodes you can use Combine Input node to refer to input values:

Checking value from Combine Input node output in n8n sub-workflow

You can find the template for the described approach here.

No comments:

Post a Comment