Naming flow with msg.topic or another variable

How can I name a flow var. like counter(msg.topic)
Or similar to this example.
I am absolutly new in this. So please no advanced answer please :slight_smile:

It's hard to understand what you are asking. You can name any variable in a msg object or in flow/global context pretty much anything you want.

It might pay you to spend some time watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Thanks but I have seen all of them and I havent seen any where they name a flow with a topic or similar.
And I am not a hardcore coder...

What do you mean by naming a flow?

I mean set flow like on the picture. But I like to name it somecontext COMBINED with the msg.topic.
something like on the picture

I am making code to control some cocarts. And I have some code that works.
But I get information from MQTT server with topics Cart1, Cart 2, Cart3 etc. So when I set a flow i need to name it with the car that is sending the information to the subflow.
not sure if you can se what I mean from some of the nodes here.
I is a mess right now but really hope you understand and can help me...
Thanks a lot

@funhall please don't post links to pastebin, as over time the link breaks and future visitors will be unable to see your flow.
The preferred method is to paste your flow directly in the forum, but please read this thread first, as it needs to be correctly formatted.

Paul
Forum Moderator

1 Like

If you are using node-red 1.3.0 or greater, you can use square brackets e.g. flow.somevariable[msg.topic]

Or in a function node..

let sv = flow.get("somevariable") || {};
sv[msg.topic] = msg.payload; //or whatever
flow.set("somevariable",sv);

Option one is quite cool and a time saver I did not know about. Is this documented somewhere?

It was added in 1.3 and described in detail in the release blog post. Not made it into the docs - although there isn't a natural home for that other than in the sidebar help for the change node... but the syntax should work in any node that uses our standard TyoedInput widget.

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