How to access a context variable in a switch node?

Hi everyone! Maybe I can't see the forest for the trees, but I thought I ask.
In a switch node, how I can access a flow's context variable? In the dropdown flow. and global. are available, but not context..
image

Thanks,
Damos

context is specific to a node (usually a function node)

as you are looking at a switch node, context is meaningless

unless I'm missing your point?

Use the flow. option - that is Flow context.

If you wanted to use Global context, you'd use the global. option.

If I'd use a function-node, it'd be a no-brainer:

myVar = context.get("theVariable");
if (myVar == "something") {
...
}

But, I'd like to use a switch node
image
The scenario above would be possible if my context variable would be flow or global:

myVar = flow.get("theVariable");
if (myVar == "something") {
...
}

can be replaced with
image
but not with a context variable.

Sorry, not getting how you could use this?

Imagine the switch node did have context - how would you set it for later usage in a comparison?

Or do you mean using the switch to access an other nodes context?

The one small part of it's own context a switch has is previous value
image

1 Like

Sure, @knolleary. But, what about the third kind of variables? I understood that

  • context.xyz is visible to the node (which people also call flow)
  • flow.xyz is visible to the flow (which people also call a tab)
  • global.xyz is visible to everything

I'd like to use context.xyz in a switch-node.

No. context.xyz is only visible to the individual node. It is only exposed in the Function node. That is not called flow.

flow.xyz is the Flow context - visible to everything on the same tab.

1 Like

Ok, got it.

So, a variable is either visible to a particular node (as context.xyz in a function node) OR to the whole tab (as flow.xyz). There's no context to a particular flow (a series of connected nodes), correct?

If correct, why not?

Correct - there is no context that is scoped to just a set of connected nodes.

Why? Because there isn't. It just isn't something that exists.

There are a number of technical reasons that makes it harder to do than you might think. A group of connected nodes has no identity in the way a tab does. If you have two disconnected groups of nodes and then you wire them together, what becomes of their individual contexts? Do they merge? If so, how does the runtime identify them? Likewise, if you have a flow which you then split into two - who gets the context?

1 Like

:slight_smile:

Thanks for the explanation, Nick. Yes, you're absolutely right. There would be a ton of consecutive problems.

Thanks to everyone!

If you want a value to be available along a series of nodes then put the data in the message and pass it on.

2 Likes

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