Accepting input from any node


my question is fairly simple. Often it happens, that I have to prepare data based on a condition, maybe load some additional data or just do something with the already existing output. This means I split the workflow path into two branches. After the work is done I want to merge back into the original branch. So I can continue and don’t have to copy nodes that basically do the same job.
This is a simple example of what I am trying to do:

This does not work however. I guess it is because the IF node returns either true or false. For example, the IF node returned true, the data was successfully prepared but the last node won’t execute because the IF node returned true and since the sheets node is linked to the false output, it won’t execute.

I believe this is expected behavior and I was naive to believe it would work that way. But is there a similar pattern? I do not want to duplicate nodes and/or whole branches just because I have to occasionally do some extra work before continuing.

Any tipp would be greatly appreciated :slight_smile:

Hey @itd24 :wave:

Welcome to the community!

There are two possible solutions that I can think of based on the information that you have provided.

Solution 1:
Instead of using the IF node to check the condition, I would do that in the Function node itself, since we are already using it to manipulate data. Based on whether the condition is true or false, I would design my function to give me the desired output.

Solution 2:
You can use the Merge node to merge data. However, I am not sure about this solution. I haven’t tested it myself.

Let me know if this helps :slight_smile:

1 Like

Thank you for your answer. The first option would not work since this was only a simple example. Another example would be:
Load data from a spreadsheet -> if there is no data -> load data from api -> merge back into the main branch and do the exactly same thing with the data regardless of it came from the api or the spreadsheet.
I will try the merge node and if it does not work I’ll try to build a node similar to the merge node that does the trick. Thanks :grin:

1 Like

Perhaps the “Execute workflow” node could help you here? It allows for you to run a different workflow as a node. Has also the added benefit of a single source of truth for a process that you use in multiple places.

It has a few different modes, so for example can even run a workflow simply from WF JSON pasted into the node’s parameters.

1 Like

This may be a solution, thank you. I’ll look further into it. :slight_smile:
I’ll solve the problem, one way or another :smiley:

So, the merge node does not work. It does not matter what the output of a node is, if the second one linked to the merge node does not get executed the merge node does not output any data.
Running different workflows won’t do any good since I can not send any data to the workflow I want to execute. Besides, having too many partial workflows can quickly become messy.

After thinking about this problem I may have found a solution. In the last few years I worked with microservices, and thus I might have had a completely wrong approach to this problem. I was treating the nodes as microservices. The funny thing is that may be a possible solution.

The idea is that every branch would save the resulting data into a table in the Postgres database. A “sub-workflow” (let’s call them sub workflows although I see it more as a sub-procedure) would be linked to a cron node. The cron node would be executed every few seconds and load all entries in the Postgres database. The entries would then be processed.

It may be a little overkill, but it would get the job done.

Btw, I am absolutely thrilled about n8n and although it may not have been meant for complicated workflows it has the potential to do exactly that :smiley:

Sorry I am totally confused. Why does the workflow from your first post not work? I can not think of a reason why it could cause problems. The node “Google Sheet1” should be executed no matter if the IF-Node has data in true or false. Can you please post an example workflow that shows the problem you have.