Accessing flow variables in a subflow via JSONata expression in a change node

I'm using a set of flows to pull some data out of a SQLite database for display in the dashboard.
The topics contain the general SQL queries with a placeholder for the table I want to access. I then use a change node with a JSONata query to replace the placeholder with the actual table name needed for the flow.
I currently am currently using flow context to store the flow specific values for the JSONata expression to pull from.

I'm trying to convert the groups of node I have on each flow into subflows for easier maintenance int eh future. But I'm having trouble finding the right syntax to access the parent flow context in the subflow JSONata expression. I see how to do it for function nodes, but I'm having trouble finding examples of using the parent flow context from other types of nodes.

I am guessing you are trying something like this

[{"id":"ad5eef7f39059301","type":"subflow","name":"Subflow 1","info":"","in":[{"x":50,"y":30,"wires":[{"id":"45c4966f7f134590"}]}],"out":[{"x":180,"y":40,"wires":[{"id":"45c4966f7f134590","port":0}]}]},{"id":"45c4966f7f134590","type":"change","z":"ad5eef7f39059301","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"$parent.test\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":80,"y":80,"wires":[[]]},{"id":"8747459b87531dd6","type":"subflow:ad5eef7f39059301","z":"d1395164b4eec73e","name":"","x":340,"y":5200,"wires":[["6e1e6aecccf74fd9"]]},{"id":"30daf90d4c913ea6","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":5160,"wires":[["74c429fed661ae92"]]},{"id":"74c429fed661ae92","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"test","pt":"flow","to":"I am here","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":5160,"wires":[[]]},{"id":"5a0781685c5f1416","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":210,"y":5200,"wires":[["8747459b87531dd6"]]},{"id":"6e1e6aecccf74fd9","type":"debug","z":"d1395164b4eec73e","name":"debug 2485","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":5200,"wires":[]}]

If not I may be best to provide an example flow.

The syntax is $flowContext("$parent.var_name")

You can find it in docs here Working with context : Node-RED

Thank you! That worked.
I had seen that info but interpreted the syntax as only being valid for the flow.get() function. Now I know better.

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