# Parent context variable accessed in subflow's first function node yields undefined?

**URL:** <https://discourse.nodered.org/t/parent-context-variable-accessed-in-subflows-first-function-node-yields-undefined/54525>\
**Category:** General\
**Created:** [30 November 2021 16:16 UTC](https://discourse.nodered.org/t/parent-context-variable-accessed-in-subflows-first-function-node-yields-undefined/54525 "2021-11-30T16:16:21Z")\
**Posts on this page:** 4\
**Page:** 3

<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:** [3 December 2021 11:57 UTC](https://discourse.nodered.org/t/parent-context-variable-accessed-in-subflows-first-function-node-yields-undefined/54525/41 "2021-12-03T11:57:03Z")

</div>

Sorry but that's exactly what the log (and the source code) shows: channels\_length is initialized with a value 6 and later in the called child subflow it's undefined.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 December 2021 12:06 UTC](https://discourse.nodered.org/t/parent-context-variable-accessed-in-subflows-first-function-node-yields-undefined/54525/42 "2021-12-03T12:06:03Z")

</div>

Sorry, come to this late. But I see that you have a `JSON.parse` in your function.

It is critical that you ALWAYS wrap `JSON` statements in a try/catch of their own. JSON is a very picky syntax and where you are trying to rely on it, you always need a way to handle an error. Having just that statement in its own try/catch should let you handle exceptions gracefully or agressively depending on need.

---

<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:** [3 December 2021 12:11 UTC](https://discourse.nodered.org/t/parent-context-variable-accessed-in-subflows-first-function-node-yields-undefined/54525/43 "2021-12-03T12:11:12Z")

</div>

Yepp, it's handled in a try-catch block 🙂

---

<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:** [1 February 2022 12:12 UTC](https://discourse.nodered.org/t/parent-context-variable-accessed-in-subflows-first-function-node-yields-undefined/54525/44 "2022-02-01T12:12:11Z")

</div>

Closed on 1 February 2022 12:12 UTC

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

[Previous page](https://discourse.nodered.org/t/parent-context-variable-accessed-in-subflows-first-function-node-yields-undefined/54525.md?page=2)
