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

**URL:** https://discourse.nodered.org/t/accessing-flow-variables-in-a-subflow-via-jsonata-expression-in-a-change-node/86441
**Category:** General
**Created:** [14 March 2024 20:45 UTC](https://discourse.nodered.org/t/accessing-flow-variables-in-a-subflow-via-jsonata-expression-in-a-change-node/86441 "2024-03-14T20:45:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Matt.L](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Matt.L](https://discourse.nodered.org/u/Matt.L)
#### Post date: [14 March 2024 20:45 UTC](https://discourse.nodered.org/t/accessing-flow-variables-in-a-subflow-via-jsonata-expression-in-a-change-node/86441/1 "2024-03-14T20:45:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [14 March 2024 21:27 UTC](https://discourse.nodered.org/t/accessing-flow-variables-in-a-subflow-via-jsonata-expression-in-a-change-node/86441/2 "2024-03-14T21:27:14Z")

</div>

I am guessing you are trying something like this

```auto
[{"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](https://nodered.org/docs/user-guide/context#context-scopes)

---

<div class="post-metadata">

### Author: ![Matt.L](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Matt.L](https://discourse.nodered.org/u/Matt.L)
#### Post date: [14 March 2024 21:52 UTC](https://discourse.nodered.org/t/accessing-flow-variables-in-a-subflow-via-jsonata-expression-in-a-change-node/86441/3 "2024-03-14T21:52:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [28 March 2024 21:53 UTC](https://discourse.nodered.org/t/accessing-flow-variables-in-a-subflow-via-jsonata-expression-in-a-change-node/86441/4 "2024-03-28T21:53:47Z")

</div>

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