Msg.topic as name for flow variable

Hi,

I am reasonable new to node-red. in my project i have a number of settings that are changeable on a dashboard. When that change comes in i want to use the msg.topic as the name for the flow variable. i tried many syntaxes and thought to have it working but then not really:

flow.set("{{msg.topic}}", msg.payload};

I tried with double and single quotes, $ sign,... but could not get it to work. i probably miss a simple syntax thing.

Regards,
Koen

use a function node

var t = msg.topic
flow.set(t,msg.payload)
return msg;

Thx zenofmud,

This works!!
I was using a function node already. It seems the input of the set command can only deal with a simple variable.

regards,
Koen

the set command expects a valid javascript property name - so as long as what you use produces that then it can be whatever you like.

This should work just as well
flow.set(msg.topic,msg.payload)

Hi Colin,

You are right. I have tried this syntax before but it didn't work. Now tried it again and it does work. I must have made another error and sent myself looking for a difficult solution... Thanks for getting me on the road again :slight_smile:

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