Flow variables in subflows

Hello everybody,
I would like to create a subflows that use their own internal variables in multiple subflow nodes

These are the characteristics:
the variables must be read and written in more nodes of the subflow.
if two subflows are positioned within the same flow, they must not read the variables of the other subflows.

I tried using the flow variables with the flow.set and flow.get functions but by placing two subflows in the same flow they access the same variables.
I also use env.set and env.get functions (I'm not sure these features exist)
I'm sure I'm missing something, but I can't figure out what.

Thanks in advance

I've accomplished similar by adding the variable to the msg object as a separate msg.part and then extract it inside the subflow. That said I'm trying to figure out a similar use case to yours on a different flow where the msg object is getting reset prior to the injection into the subflow (I've used a join workaround to reattach my variable msg.part right before the subflow but would like a simpler solution if you figure one out)

1 Like

I was thinking of doing a similar thing too. however, I was hoping for a simpler solution such as the global and flow variables

My understanding is that each instance of a subflow will have its own flow context. If a subflow is used twice then the flow contexts should be separate between them.

2 Likes

Exactly, is there anyone who has ideas?

1 Like

Each subflow instance gets its own flow context. If you have an example flow that shows that not working as described, please share so we can investigate

If you want the subflows to share context then you can access the parent flow context using $parent.variable as described in the docs
.

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