Sending multiple msg from function node

Hello!
In a function node, i get (as input) an array of multiple objects. Now i want to extract one string from each object (all objects are built the same) and send each string separately over one node-output.
Is that possible?

Thanks in advance
Robin

Are you wanting to send all the messages out the same output?

If yes:

You do a node.send() command, rather than the return msg command.

So...

You would get the incoming message, split it up into the required bits and then node.send() for each part.

That is a real basic overview but I hope it helps.

Dunno how good this example is, but.....

[{"id":"7ff1fa4571033fb7","type":"function","z":"7e987ddf260bdf0d","name":"function 44","func":"let x = msg.payload;\nlet vA = msg.payload[1];\nlet vB = msg.payload[2];\nlet vC = msg.payload[3];\n\nlet msg1 = {\"payload\":vA};\nlet msg2 = {\"payload\":vB};\nlet msg3 = {\"payload\":vC};\n\nnode.send(msg1);\nnode.send(msg2);\nnode.send(msg3);","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2890,"y":4650,"wires":[["b832f9bd4fd872a8"]]},{"id":"41e8f1532772ef96","type":"inject","z":"7e987ddf260bdf0d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"1\":\"a\",\"2\":\"b\",\"3\":\"c\"}","payloadType":"json","x":2680,"y":4650,"wires":[["7ff1fa4571033fb7","a7d27cc3363f8782"]]},{"id":"b832f9bd4fd872a8","type":"debug","z":"7e987ddf260bdf0d","name":"Split","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":3160,"y":4650,"wires":[]},{"id":"a7d27cc3363f8782","type":"debug","z":"7e987ddf260bdf0d","name":"Going in","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2880,"y":4600,"wires":[]}]
1 Like

A low-code approach without using a function node:

[{"id":"1c22da8356c1b02b","type":"inject","z":"5c74cb9708ad35f2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":220,"wires":[["cb5500dc47be6855"]]},{"id":"cb5500dc47be6855","type":"change","z":"5c74cb9708ad35f2","name":"Input data","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"artist\":\"Poussin\",\"work\":\"Et in Arcadia Ego\"},{\"artist\":\"Van Eyck\",\"work\":\"St Barbara\"},{\"artist\":\"Rembrandt\",\"work\":\"An Elephant\"}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":220,"wires":[["605df9858753148e","bc24dc603eef50db"]]},{"id":"605df9858753148e","type":"change","z":"5c74cb9708ad35f2","name":"\"work\" property of each array element","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.work","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":280,"wires":[["b9fe67ee07bd5811"]]},{"id":"e96ea5c80297c7da","type":"debug","z":"5c74cb9708ad35f2","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":280,"wires":[]},{"id":"b9fe67ee07bd5811","type":"split","z":"5c74cb9708ad35f2","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":650,"y":280,"wires":[["e96ea5c80297c7da"]]},{"id":"bc24dc603eef50db","type":"debug","z":"5c74cb9708ad35f2","name":"Input data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":220,"wires":[]}]
1 Like

Thanks, that is exactly, what i was searching for!

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