I have a incoming msg.payload.Name, which I want to split.
The msg.payload.Name always starts with Watts , which is what I want to split.
Examples for msg.payload.Name are
Watts Power TV
Watts Kitchen TV
So if I have 'Watts Power TV' in msg.payload.Name, I want to have msg.payload.Name 'Power TV'
I have tried this in a function node but it doesnt work
const n = msg.payload.Name;
msg.payload.name = n.slice(msg.payload.Name, 5)
return msg;
If you use the built in helper tools you will avoid the guess work...
There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
Basically it is NOT msg.payload.name nor is it msg.payload.nodeName - so use the copy path button
If you play a bit with the buttons that SteveMcl showed you, you will see that this particular message has:
msg.topic (equals "sync")
msg.nodeName (equals "Watts Lounge TV")
msg.payload (an object comprising msg.payload.ref, msg.payload.name [ equals "Watts Lounge TV" ], msg.payload.location, etc)
So it's up to you if you operate on msg.nodeName or msg.payload.name. But whichever you pick, stick to your choice and pay attention to precise naming and upper/lower case.
Personally I'd stick with msg.payload.name but no very good reason for that choice.
Looked at the debug info again. I thought it should be msg.payload.name, but it isnt, same error. But I tried
const n = msg.nodeName;
msg.nodeName = n.slice(6);
return msg;
Thats working. Great. But dont really understand why msg.payload.name did not work.
But copying from the debug node does help me for the future, I thought I had it worked out how to get to message data. Obviously still have to learn !
Yoyr help is much appreciated !