# Calling Environment Variables in Change Node for Global Variable name

**URL:** <https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747>\
**Category:** General\
**Created:** [20 April 2023 16:22 UTC](https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747 "2023-04-20T16:22:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KAMERONSWENSON](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@KAMERONSWENSON](https://discourse.nodered.org/u/KAMERONSWENSON)\
**Post date:** [20 April 2023 16:22 UTC](https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747/1 "2023-04-20T16:22:30Z")

</div>

Hello Everyone,

I am building a flow that contains a large amount of subflows. Within these subflows you find one node named ArrayDefect"X". X being an identifier. I have to set these array for each individual machine that I add to this flow. We have around 80+ machines at our plant.

**QUESTION:** Is there a way to use an environment variable or pass a variable on to the end of these nodes that I can specify per subflow as a 1, 2, 3, 4, etc. ? That way when I just copy and paste all I have to do is add an environment variable of the number I want and just reference that number? I know its possible to set a environment variable in the value field but is it possible in the naming field?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f8585858df08be899592bf9afbdbfbcf5c3d059.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/2327093369b040c305071e8315f487d706983dc7.png)

Thank you!

---

<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:** [20 April 2023 16:30 UTC](https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747/2 "2023-04-20T16:30:21Z")

</div>

Not sure of sturcture of ArrayDefect, but if it is an object or array, you can do.

 ![chrome_screenshot_1682008272593](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/484a36120620fb374f7601ca1f89a3808ecf2f8a.png)  
Otherwise you would have to use a function node.

```auto
let envr = env.get("evr_name") ?? "0";
msg["ArrayDefect" + envr] = msg.payload;
return msg;

```

---

<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:** [20 April 2023 16:39 UTC](https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747/3 "2023-04-20T16:39:07Z")

</div>

You cannot replace part of an input value with an env variable - from the docs:

> This only works if it replaces the entire property - it cannot be used to substitute just part of the value. For example, it is _not_ possible to use `CLIENT-${HOST}` .

Use a function node instead.

---

<div class="post-metadata">

**Author:** ![KAMERONSWENSON](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@KAMERONSWENSON](https://discourse.nodered.org/u/KAMERONSWENSON)\
**Post date:** [20 April 2023 16:48 UTC](https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747/4 "2023-04-20T16:48:11Z")

</div>

Could you send me a flow id of you getting this to work. I keep getting undefined when calling the global variable.

---

<div class="post-metadata">

**Author:** ![KAMERONSWENSON](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@KAMERONSWENSON](https://discourse.nodered.org/u/KAMERONSWENSON)\
**Post date:** [20 April 2023 16:51 UTC](https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747/5 "2023-04-20T16:51:39Z")

</div>

nvm I was able to get this to work. Thank you!

---

<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:** [4 May 2023 16:51 UTC](https://discourse.nodered.org/t/calling-environment-variables-in-change-node-for-global-variable-name/77747/6 "2023-05-04T16:51:42Z")

</div>

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