I want to set a variable like $id that I can use anywhere in the workflow. A few different nodes might set it, so I can’t reference the node. Ideally, I would like to:
Set it like: var $id = "123"
And use it in a node like: $id.
On the left side panel you should see all available variables that you can drag and drop. If you don’t see anything that might be because to forgot to run the previous node.
Note: If there is an error in previous node you would also have to resolve it before you see the information in the left side panel.
Sorry I a little bit confused. In the beginning of the workflow you would create $id in Crypto node and then reference to it by this node name. Do I miss something?
Take look at this course created by N8N team. Level One
I appreciate all the responses. Maybe I wasn’t clear. Please look at my initial workflow. Depending on the response of an IF Node, two different nodes will return an “id”. I don’t know which one, so I don’t know the name of the node. How can I get the data if I don’t know the name of the node?
It is a fairly new feature, so… (Edit: Apparently that’s not true per one of the n8n guys, but still…). be sure to test thoroughly… so see if $getWorkflowStaticData does what you need.
Edit: It is not exactly clear in the documentation whether this data is scoped to a specific execution of a workflow, or to the instance of n8n, crossing multiple executions of the workflow. The variable name “lastExecution” in the docs subtly suggests it is the latter, so I tested a bit to see how it works across multiple executions. I confirmed that a value set in one execution does persist to be read back in during later executions.
However, I also ran multiple executions of a workflow concurrently, where a “static data” variable gets set at the beginning, and checked at the end, to see if workflow executions were “stepping on” each other’s data, but… I couldn’t get that to fail, so maybe it is “thread safe” (so to speak). I would probably do some more testing before depending on this behavior in a production workflow.
Please mark this as the solution if it’s what you needed to get things working. Thanks.