VERY VERY URGENT: Cant access variable

I really dont know what is happening but I cant find a way to access a variable that I set with edit fields and want to access later… its not passed with every node since there is HTTP calls and switch nodes but how do I fix a variable?

How do I pass global variables that I want to access across the entire workflow? Is this so hard… like wtf?


The oringinal one has sensitive information but I replciated it to show what I mean… it illustrates it perfectly

if you simply remove the HTTP request it works and outputs the variable as manual. As soon as you include it the last code node returns an empty object. This is my basic problem

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

{{$(‘Edit Fields1’).first()}} can you access the first item?

Very wierd fix, but it does the job if you are very urgent,

Use Workflow Static Data to access variables anywhere in your workflow:

// To save a variable (in any Function node):
await $setWorkflowStaticData("global", {
  myVariable: "my value"
});

// To access it anywhere else:
const myVar = await $getWorkflowStaticData("global").myVariable;

This works across all branches, HTTP calls, and switch nodes because it’s stored with the workflow, not passed between nodes.

If my quick solution helps solve your urgent issue, please mark it as the answer! :arrows_counterclockwise::+1:

2 Likes

How would I ask for that value then in my switch node? I am currently just asking

$json.whichflow → String equals
„Myflow“

I can’t access it via passing the exact node cause I have 5 different triggers which all set this variable differently

Ok well if the node is accesible from that node, you either need to rework your flow or think about using global variables.

That’s what I am asking how would I use global variables?
And how would I check them in a Switch statement

How come this is so unnecessarily hard to realize

you set them in your UI(similar to adding a cred), and then I believe you reference them with $vars.<var_name>. I don’t think you need them though, you just need to rework your workflow.

What do you mean rework? I have multiple inputs and want to set a variable which checks which input node the trigger came from.

Well if trying to explicitly accessing the node with an expression doesn’t work, that means that the data is not getting to that node. Share your whole workflow json plz

1 Like

The oringinal one has sensitive information but I replciated it to show what I mean… it illustrates it perfectly

if you simply remove the HTTP request it works and outputs the variable as manual. As soon as you include it the last code node returns an empty object. This is my basic problem

well you’re not even defining “items” inside the code node. something like const items = input.all

that one doesn’t work either. Cant access it after the HTTP call… isn’t there any way to set this variable globally and access it? Cause its never overwritten, its just accessed to check based on switches

@Daniel_Lamphere do you have a solution for this?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.