# Set Parameter to Subflow's Environment Variables from a Function

**URL:** <https://discourse.nodered.org/t/set-parameter-to-subflows-environment-variables-from-a-function/25599>\
**Category:** General\
**Created:** [27 April 2020 07:52 UTC](https://discourse.nodered.org/t/set-parameter-to-subflows-environment-variables-from-a-function/25599 "2020-04-27T07:52:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikeh](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mikeh](https://discourse.nodered.org/u/mikeh)\
**Post date:** [27 April 2020 07:52 UTC](https://discourse.nodered.org/t/set-parameter-to-subflows-environment-variables-from-a-function/25599/1 "2020-04-27T07:52:08Z")

</div>

I have a Subflow named: Get Price Factor. That subflow has 2 Environment Variables named cost and sku.  
Now before the subflow is called, there's a function named "Get Item Cost".  
I want to set both cost and sku from the function "Get Item Cost".  
Is this possible?

 ![2020-04-27_1548](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/1505e11acd91c2f3357a3a91d5f754c2d4835cd0.png)

---

<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:** [27 April 2020 07:59 UTC](https://discourse.nodered.org/t/set-parameter-to-subflows-environment-variables-from-a-function/25599/2 "2020-04-27T07:59:52Z")

</div>

No that is not possible. Environment Variables cannot be changed dynamically at runtime.

If you want dynamic information in the subflow, you need to pass it in with the message.

---

<div class="post-metadata">

**Author:** ![mikeh](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mikeh](https://discourse.nodered.org/u/mikeh)\
**Post date:** [27 April 2020 08:07 UTC](https://discourse.nodered.org/t/set-parameter-to-subflows-environment-variables-from-a-function/25599/3 "2020-04-27T08:07:27Z")

</div>

Bummer, I was hoping some solution to it.  
Which is better? Pass it with the message or set a flow variable which I can access in the subflow?

---

<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:** [27 April 2020 08:26 UTC](https://discourse.nodered.org/t/set-parameter-to-subflows-environment-variables-from-a-function/25599/4 "2020-04-27T08:26:00Z")

</div>

If you set it as a flow context variable then you have to figure out how to get each instance to see its own value and not everyone else's.

It depends on the exact scenario, but in general passing it in with the message is the better way to do it.

---

<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:** [26 June 2020 08:26 UTC](https://discourse.nodered.org/t/set-parameter-to-subflows-environment-variables-from-a-function/25599/5 "2020-06-26T08:26:00Z")

</div>

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