I’m building a workflow where I need to pass variables between nodes, especially when those nodes are not directly connected. I’ve encountered issues where some nodes don’t execute, and when I try to reference the data in a later node, it gets stuck or returns undefined.
What I’ve Tried So Far:
Set Node – I attempted to store variables using the Set Node, but because it’s separated from the main execution flow, some instances of the node didn’t execute. As a result, when a later node tried to reference the variable, the data wasn’t available, causing issues.
Referencing with $node[“Node Name”].json[“key”] – This works in some cases, but when nodes are not executed due to being outside the main flow, the values are missing.
Merge Node – This helps when combining multiple data sources, but it doesn’t solve cases where I need to persist data for later use in a disconnected node.
My Question:
What is the best way to store and pass variables between nodes that are not directly connected?
How can I ensure that variables persist correctly and are reliably accessible, even when the node that sets them is not part of the main execution flow?
If anyone has encountered and solved this issue in n8n, I’d appreciate your insights! Thanks in advance.
dont just activate your own flows on me…
that is a general question that wants to understand how to use the platform in the most correct way. currently, I couldn’t find any answers in the documentation or any other source…
Just asking the community for best practices…
Thanks…
During testing that doesn’t happen, but during execution every branch gets executed.
So theoretically you could retrieve values from nodes that are not in the same branch.
But ideally you want to pass data to the same branch. Because you could lose the items reference if you mess up the data (see item linking).
The best way to pass data from multiple branches forward is indeed the Merge node. It is a very flexible node that allows you to merge data in many ways.
Alternatively you could use the Code node with a custom written JavaScript or Python code. You can ask ChatGPT to generate that for you.
I hope this helps.
If my reply answers your question, please remember to mark it as a solution.
I dont want to connect everything to the final node because then, it activates the final node before others finished (since it is part of the upper branch).
What is the actual syntax then, that I can use in my final ‘HTML’ node, to reference the data that is waiting in the ‘Hold article’ (Set) node? No matter what I do - I cant reference that variable without actually connecting the node, which then - breaks my flow too.
In your example you don’t actually need to branch off just like gmsalomao2 suggested.
If you do need branches for different logic though you can have multiple workflows and use the Execute Sub-Workflow node and trigger.
For example this workflow checks if a summary of an Airtable record is empty.
If it is it generates it and calls a sub-workflow.
If it’s not it goes directly to the same sub-workflow.
Initially i did it just like you did and merged back in but i ran into the same issue.
Beside the sub-workflow split i know there are custom variables that you can set with very simple code node Create custom variables | n8n Docs but they are available only in the higher tier paid plans