Problem with flow-variables

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.

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

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).

I've changed it to "General".

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

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

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

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

1 Like

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.

1 Like

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