# Part 2: Parent context variable accessed in subflow’s first function node yields undefined?

**URL:** https://discourse.nodered.org/t/part-2-parent-context-variable-accessed-in-subflow-s-first-function-node-yields-undefined/59362
**Category:** Core Development
**Created:** [4 March 2022 12:50 UTC](https://discourse.nodered.org/t/part-2-parent-context-variable-accessed-in-subflow-s-first-function-node-yields-undefined/59362 "2022-03-04T12:50:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)
#### Post date: [4 March 2022 12:50 UTC](https://discourse.nodered.org/t/part-2-parent-context-variable-accessed-in-subflow-s-first-function-node-yields-undefined/59362/1 "2022-03-04T12:50:01Z")

</div>

The existing thread with the same topic got closed automatically so continuing it here...

Managed to make a minimal flow which can reproduce the issue on 2.2.2 and made a video of it. However, it still cannot be reproduced all the time...

I [shared the video](https://drive.google.com/file/d/1Jrl7F8bvFLgtAfSGX1jM8gHq5CHzpvXs/view?usp=sharing) on my google drive.

The flow contains two subflows of which subflow 1 receives a msg.payload from an inject node and stores that payload in a flow context variable:

```auto
let b=0;
node.warn(msg.payload);
flow.set("test",msg.payload);
return msg;

```

Then it calls subflow 2 which contains a function to get the same variable set in its parent:

```auto
let a=1;
node.warn(flow.get("$parent.test"));
return msg;

```

When I first click the inject, the node.warn() in subflow 1 logs the payload received (true) on the debug pane and the node.warn() in subflow 2 logs the value (undefined) of the variable read from the parent context.

Then I simply change an unnecessary code line (changing let a=0 to let a=1) in the function of subflow 2 just to be able to trigger a deploy. After that, injecting a payload to subflow 1 results in logging the same value (true) by both subflows.

Here is the flow exported:

```auto
[
    {
        "id": "f70d4fc3.c71c38",
        "type": "subflow",
        "name": "Subflow 2",
        "info": "",
        "in": [
            {
                "x": 80,
                "y": 80,
                "wires": [
                    {
                        "id": "e7a1deed.3d9288"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 320,
                "y": 80,
                "wires": [
                    {
                        "id": "e7a1deed.3d9288",
                        "port": 0
                    }
                ]
            }
        ]
    },
    {
        "id": "e7a1deed.3d9288",
        "type": "function",
        "z": "f70d4fc3.c71c38",
        "name": "",
        "func": "let a=1;\nnode.warn(flow.get(\"$parent.test\"));\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 200,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "70f7ac75.ea8e34",
        "type": "subflow",
        "name": "Subflow 1",
        "info": "",
        "in": [
            {
                "x": 80,
                "y": 80,
                "wires": [
                    {
                        "id": "48517af6.d85314"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 480,
                "y": 80,
                "wires": [
                    {
                        "id": "ab5276b6.32ea1",
                        "port": 0
                    }
                ]
            }
        ]
    },
    {
        "id": "48517af6.d85314",
        "type": "function",
        "z": "70f7ac75.ea8e34",
        "name": "",
        "func": "let b=0;\nnode.warn(msg.payload);\nflow.set(\"test\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 190,
        "y": 80,
        "wires": [
            [
                "ab5276b6.32ea1"
            ]
        ]
    },
    {
        "id": "ab5276b6.32ea1",
        "type": "subflow:f70d4fc3.c71c38",
        "z": "70f7ac75.ea8e34",
        "name": "",
        "env": [],
        "x": 360,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "aa2b5804.9cad4",
        "type": "subflow:70f7ac75.ea8e34",
        "z": "fb075204.b32578",
        "name": "",
        "env": [],
        "x": 340,
        "y": 540,
        "wires": [
            []
        ]
    },
    {
        "id": "ec2e7096.f0e618",
        "type": "inject",
        "z": "fb075204.b32578",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 170,
        "y": 540,
        "wires": [
            [
                "aa2b5804.9cad4"
            ]
        ]
    }
]

```

---

<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: [10 March 2022 11:13 UTC](https://discourse.nodered.org/t/part-2-parent-context-variable-accessed-in-subflow-s-first-function-node-yields-undefined/59362/2 "2022-03-10T11:13:04Z")

</div>

Please either stick to forum or Issue tracker.

Issue raised here: [Parent context variable accessed in subflow’s first function node yields undefined · Issue #3485 · node-red/node-red · GitHub](https://github.com/node-red/node-red/issues/3485)

Closing this thread to reduce duplication.

---

<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: [10 March 2022 11:13 UTC](https://discourse.nodered.org/t/part-2-parent-context-variable-accessed-in-subflow-s-first-function-node-yields-undefined/59362/3 "2022-03-10T11:13:10Z")

</div>


