STRING node - stuck SOLVED! Sorry!

Sorry folks. Seems the elephant is back in the room.

This is the bare bones of what I am wanting to do:

[{"id":"77182547.31a85c","type":"string","z":"d52027c9.60c9f8","name":"","methods":[{"name":"chompLeft","params":[{"type":"str","value":"COMMAND_REPLY"}]}],"prop":"topic","propout":"payload","object":"msg","objectout":"msg","x":430,"y":140,"wires":[["b4edeabd.882af"]]},{"id":"b4edeabd.882af","type":"debug","z":"d52027c9.60c9f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","x":600,"y":140,"wires":[]},{"id":"ec25ae89.d3cb7","type":"inject","z":"d52027c9.60c9f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":140,"wires":[["957dca8c.5f4d88"]]},{"id":"957dca8c.5f4d88","type":"function","z":"d52027c9.60c9f8","name":"","func":"msg.topic = \"COMMAND_REPLY/TimePi\";\nmsg.payload = \"Test message\"\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":140,"wires":[["77182547.31a85c"]]}]

Idea:
The topic is “COMMAND_REPLY/(device name)”
and I want to strip that to “device name”.

I use the STRING node and CHOMPLEFT COMMAND_REPLY/ of the topic.

But it doesn’t seem to be working.

Where’s the elephant?

AH!

STRING node returns its results in PAYLOAD irrespective of from where the input was sourced!
I was playing with (msg.)topic and expected the result to REMAIN in topic.

Seems it is put in payload.

Nice if that was declared a bit clearer. Is it?

I think you’ve just mis-read it.

You can change the output to be delivered in msg.topic instead of msg.payload

Yup. Classic foot in mouth for me.

JFI the node-red-contrib-string node doesn’t actually work on my Win10 setup so it may not be a reliable node to use

I’d recommend rolling your own function node or using a change node with a bit of JSONata instead

[edit]Duff gen see later post[/edit]

Can you provide a minimal flow showing the problem please? I would have expected it to work ok.

I would use a change node to do this… Set msg. topic to the J: expression
topic.$substringAfter("/")

oops - my error - didn’t realise that OP had changed debug node to show topic - it is working for me :slight_smile:

Thanks Steve.

I got fooled by not looking at the bottom of the window where it sets the output part.

So as much as I set it to parse the msg.TOPIC, I didn’t set it to return the result in msg.topic.

Worked around the problem in the mean time.

All good.

Thanks.