# Subflow environment variables issue (\_info, \_type)

**URL:** https://discourse.nodered.org/t/subflow-environment-variables-issue-info-type/26894
**Category:** General
**Created:** [19 May 2020 06:18 UTC](https://discourse.nodered.org/t/subflow-environment-variables-issue-info-type/26894 "2020-05-19T06:18:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![offreal](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/offreal/32/22335_2.png) [@offreal](https://discourse.nodered.org/u/offreal)
#### Post date: [19 May 2020 06:18 UTC](https://discourse.nodered.org/t/subflow-environment-variables-issue-info-type/26894/1 "2020-05-19T06:18:08Z")

</div>

Hi,  
I created simple subflow with one input, and one output.  
Subflow has 3 properties: unit\_test, unit\_type, unit\_tell. All of them are dropdowns with two options and string values.  
Inside subflow there are function, that reads environment variables:

```auto
msg.env = [env.get("unit_test"), env.get("unit_type"), env.get("unit_tell")];
return msg;

```

On my flow, at subflow output I got this: `["opt1",null,"asdf"]`

It means, that `env.get("unit_type")` always return `null`.  
I tested this on multiple PCs and there is always this problem.  
What wrong with `"unit_type"`?

Node-red version: 1.0.6  
Nodes to test:

```auto
[{"id":"818111e.14a84f","type":"subflow","name":"test","info":"","category":"","in":[{"x":600,"y":320,"wires":[{"id":"aac98841.4feec8"}]}],"out":[{"x":880,"y":320,"wires":[{"id":"aac98841.4feec8","port":0}]}],"env":[{"name":"unit_test","type":"str","value":"opt1","ui":{"icon":"font-awesome/fa-arrow-circle-down","label":{"en-US":"Unit test"},"type":"select","opts":{"opts":[{"l":{"en-US":"opt1"},"v":"opt1"},{"l":{"en-US":"opt2"},"v":"opt2"}]}}},{"name":"unit_type","type":"str","value":"aaa","ui":{"icon":"font-awesome/fa-align-left","label":{"en-US":"Unit type"},"type":"select","opts":{"opts":[{"l":{"en-US":"aaa"},"v":"aaa"},{"l":{"en-US":"bbb"},"v":"bbb"}]}}},{"name":"unit_tell","type":"str","value":"asdf","ui":{"icon":"font-awesome/fa-compass","label":{"en-US":"Unit tell"},"type":"select","opts":{"opts":[{"l":{"en-US":"asdf"},"v":"asdf"},{"l":{"en-US":"qwer"},"v":"qwer"}]}}}],"color":"#DDAA99"},{"id":"aac98841.4feec8","type":"function","z":"818111e.14a84f","name":"","func":"msg.env = [env.get(\"unit_test\"), env.get(\"unit_type\"), env.get(\"unit_tell\")];\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":320,"wires":[[]]},{"id":"259922d3.db2c6e","type":"debug","z":"f31cfc67.f14fb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":830,"y":1840,"wires":[]},{"id":"a85acf85.0a113","type":"subflow:818111e.14a84f","z":"f31cfc67.f14fb","name":"","env":[{"name":"unit_type","value":"bbb","type":"str"}],"x":660,"y":1840,"wires":[["259922d3.db2c6e"]]},{"id":"555ec225.0c57bc","type":"inject","z":"f31cfc67.f14fb","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":480,"y":1840,"wires":[["a85acf85.0a113"]]}]

```

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [19 May 2020 07:00 UTC](https://discourse.nodered.org/t/subflow-environment-variables-issue-info-type/26894/2 "2020-05-19T07:00:12Z")

</div>

This is really strange. I see the same thing when importing your flow. Everything seems right. It’s just like it wasn’t there 🤔  
maybe @dceejay or @knolleary can have a look as this indeed looks like a bug unless we are booth missing something obvious here, which could be as i only had one cup of coffee so far ☕ .

---

<div class="post-metadata">

### Author: ![offreal](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/offreal/32/22335_2.png) [@offreal](https://discourse.nodered.org/u/offreal)
#### Post date: [19 May 2020 07:51 UTC](https://discourse.nodered.org/t/subflow-environment-variables-issue-info-type/26894/3 "2020-05-19T07:51:27Z")

</div>

Looks like, its not bug 🤔

I found this:

`node-red-master\packages\node_modules\@node-red\runtime\lib\nodes\flows\Subflow.js`

```auto
    /**
     * Get environment variable of subflow
     * @param {String} name name of env var
     * @return {Object} val value of env var
     */
    getSetting(name) {
        this.trace("getSetting:"+name);
        if (!/^\$parent\./.test(name)) {
            var env = this.env;
            var is_info = name.endsWith("_info");
            var is_type = name.endsWith("_type");
            var ename = (is_info || is_type) ? name.substring(0, name.length -5) : name; // 5 = length of "_info"/"_type"

```

Using `"*_info"` as parameter name leads to the same behavior.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [19 May 2020 08:03 UTC](https://discourse.nodered.org/t/subflow-environment-variables-issue-info-type/26894/4 "2020-05-19T08:03:56Z")

</div>

Hmm, yes - that is an unfortunate naming collision. We need to fix that to reduce the chances of a clash with the internal property names.

So yes, I would call it a bug on the basis that you had every right to expect your flow to work and it didn't because of an internal implementation detail.

---

<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: [18 July 2020 08:03 UTC](https://discourse.nodered.org/t/subflow-environment-variables-issue-info-type/26894/5 "2020-07-18T08:03:58Z")

</div>

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