# Problem with flow-variables

**URL:** <https://discourse.nodered.org/t/problem-with-flow-variables/30734>\
**Category:** General\
**Created:** [26 July 2020 15:52 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734 "2020-07-26T15:52:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spunckie](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@Spunckie](https://discourse.nodered.org/u/Spunckie)\
**Post date:** [26 July 2020 15:52 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/1 "2020-07-26T15:52:46Z")

</div>

I want to start a flow for all items in an array. This works fine as long as I don't use flow.set oder flow.get-statement. A debug-note after the function-node that start the flow for all Items shows the right msg.payload for each item.  
I tried to start the flow via push oder node.send. In the first function-Node is a flow.set-statement "flow.set('myVar', msg.payload)" and at the last function-Node is a flow.get statement "msg.payload = flow.get('myVar')". After this function-node I added a debug-node As long as there is only one item in the array, everything works fine. The debug-node shows the right value. Unfortunately nothing is fine, if there is more than one item in the array. The debug-node shows for each Item the same value.  
Unfortunately as a new user I'am not allowed to upload an example.  
Any Ideas to solve this problem? Thanks a lot in advance.

---

<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:** [26 July 2020 15:55 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/2 "2020-07-26T15:55:07Z")

</div>

Hi, you may wish to change the category since "Creating Nodes" is about developing custom nodes rather than dealing with flow questions.

---

<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:** [26 July 2020 15:58 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/3 "2020-07-26T15:58:19Z")

</div>

Not sure I'm really understanding your problem. But at first sight, I don't think you need the set/get at all. Just add the data to the msg and your 2nd function node will have it right there. There is no overhead for doing this (except when 1 node has 2 or more wires attached to the output since then Node-RED will clone the object - but if you are just using that to add a debug node, you can either disable or remove the debug once things are working).

---

<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:** [26 July 2020 15:58 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/4 "2020-07-26T15:58:52Z")

</div>

I've changed it to "General".

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 July 2020 16:07 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/5 "2020-07-26T16:07:42Z")

</div>

PS - Have bumped you up so you should be able to attach now

---

<div class="post-metadata">

**Author:** ![Spunckie](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@Spunckie](https://discourse.nodered.org/u/Spunckie)\
**Post date:** [26 July 2020 16:16 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/6 "2020-07-26T16:16:21Z")

</div>

Thank you. This would be the best way. But I use a HTTP-Request-Node. That's I have to store the msg.payload because I need the value after the Request-Node

---

<div class="post-metadata">

**Author:** ![Spunckie](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@Spunckie](https://discourse.nodered.org/u/Spunckie)\
**Post date:** [26 July 2020 16:18 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/7 "2020-07-26T16:18:21Z")

</div>

Thank you! But I am still not allowed to upload.

---

<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:** [26 July 2020 16:38 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/8 "2020-07-26T16:38:06Z")

</div>

> [@Spunckie](#):
>
> That's I have to store the msg.payload because I need the value after the Request-Node

You can copy the payload to another message property using a Change node. No need to put it into flow context.

---

<div class="post-metadata">

**Author:** ![Spunckie](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@Spunckie](https://discourse.nodered.org/u/Spunckie)\
**Post date:** [26 July 2020 17:41 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/9 "2020-07-26T17:41:33Z")

</div>

Thank you. That is the solution and it seems to work perfectly! My flow is more difficult as I explained because it has some sub-flows and these sub-flows have other sub-flows again. So I have to take care, that the property is always there. I think this should to be realized. So easy but I was so focused on the "set/get-functionality, that I was not able get an other idea. That's why your advise is very useful for me.

---

<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:** [9 August 2020 17:41 UTC](https://discourse.nodered.org/t/problem-with-flow-variables/30734/10 "2020-08-09T17:41:36Z")

</div>

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