# How to pass flow.get("variable") to subflow?

**URL:** <https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503>\
**Category:** General\
**Created:** [21 December 2022 02:20 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503 "2022-12-21T02:20:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![namexx](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/namexx/32/72976_2.png) [@namexx](https://discourse.nodered.org/u/namexx)\
**Post date:** [21 December 2022 02:20 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503/1 "2022-12-21T02:20:59Z")

</div>

Hi, im begginer on this world of the node-red.

Im trying to pass the value of a type flow variable. This to be worked on in a subflow.

How cand send variable to subflow?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/328aa6a74f0ecd58328dd71ea9e23ef546a9308b.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 December 2022 07:05 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503/2 "2022-12-21T07:05:51Z")

</div>

In the subflow you can access the flow variables of the parent flow like:

```auto
flow.get("$parent.myVariable")

```

and for variables use:

```auto
$env("VarMax")

```

---

<div class="post-metadata">

**Author:** ![namexx](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/namexx/32/72976_2.png) [@namexx](https://discourse.nodered.org/u/namexx)\
**Post date:** [21 December 2022 08:52 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503/3 "2022-12-21T08:52:51Z")

</div>

> [@bakman2](#):
>
> `$env("VarMax")`

Hi, bakman your repley its work. Now I have some questions:

In node inject how can do this? -\> flow.$parent.$env("counter")

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f905d9dbb933d40e6c79b914a48eb5e403cf13df.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b21e90779b63a6757d686c786c6868fb0d61c417.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 December 2022 09:27 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503/4 "2022-12-21T09:27:55Z")

</div>

The much better (and portable/reusable/pure) way to do this is to add variables to the `msg` then you simply pick them up in the subflow.

Main flow...  
inject (`msg.payload` ← `flow.contador0`) → Subflow → debug

Subflow...  
Input → function (use `msg.payload`) → output

* * *

Accessing parent flow variables is basically for async problems, reduced portability of code etc etc.

---

<div class="post-metadata">

**Author:** ![namexx](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/namexx/32/72976_2.png) [@namexx](https://discourse.nodered.org/u/namexx)\
**Post date:** [21 December 2022 11:41 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503/5 "2022-12-21T11:41:37Z")

</div>

Thanks for your replay!

but i do dont understand what you are trying to explain. 😣

Please you can add code example 😄

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 December 2022 12:53 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503/6 "2022-12-21T12:53:54Z")

</div>

If you are new to node-red and its concepts I would recommend to avoid subflows for now. Also note that you cannot use inject nodes inside a subflow.

---

<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:** [19 February 2023 12:54 UTC](https://discourse.nodered.org/t/how-to-pass-flow-get-variable-to-subflow/72503/7 "2023-02-19T12:54:36Z")

</div>

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