# Naming flow with msg.topic or another variable

**URL:** <https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171>\
**Category:** General\
**Created:** [1 August 2021 20:07 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171 "2021-08-01T20:07:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [1 August 2021 20:07 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/1 "2021-08-01T20:07:11Z")

</div>

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 🙂

> **[Untitled - Pastebin.com](https://pastebin.com/PQgA0i9c)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 August 2021 20:21 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/2 "2021-08-01T20:21:38Z")

</div>

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](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). 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.

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [1 August 2021 20:39 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/3 "2021-08-01T20:39:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 August 2021 20:56 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/4 "2021-08-01T20:56:57Z")

</div>

> [@funhall](#):
>
> name a flow

What do you mean by naming a flow?

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [1 August 2021 21:00 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/5 "2021-08-01T21:00:36Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/221a9f4598eb4134c1cfe7518ea3017f930a151e.png)

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [1 August 2021 21:04 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/6 "2021-08-01T21:04:31Z")

</div>

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

> **[Untitled - Pastebin.com](https://pastebin.com/Wuy7GgZW)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [1 August 2021 21:24 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/7 "2021-08-01T21:24:59Z")

</div>

@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](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) first, as it needs to be correctly formatted.

Paul  
Forum Moderator

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 August 2021 21:28 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/8 "2021-08-01T21:28:15Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)\
**Post date:** [1 August 2021 21:45 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/9 "2021-08-01T21:45:24Z")

</div>

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

---

<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:** [1 August 2021 21:58 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/10 "2021-08-01T21:58:57Z")

</div>

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.

> **[Version 1.3 released](https://nodered.org/blog/2021/04/08/version-1-3-released#referencing-msg-properties-in-change-switch-nodes)**
>
> Find out more on the blog

---

<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:** [30 September 2021 21:59 UTC](https://discourse.nodered.org/t/naming-flow-with-msg-topic-or-another-variable/49171/11 "2021-09-30T21:59:48Z")

</div>

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