Hello people,
I’ve got a question regarding the join and create an array out of x elements. What I want is to create an array out of two other elements. Until now I am able to make incomplete arrays.
I noticed when you set the join function to automatic and set in the msg.parts the proper values. In this case msg.parts.count = 2, msg.parts.id = aa55 and one has msg.parts.index = 0 and the other msg.parts.index = 1
The join will make a an array as soon the amount of msg.payloads that are received by the join met the value of msg.parts.count. When there are two msg’s with msg.parts.index = 1, it will create an array with [null, (2nd message of msg.parts.index = 1] and throws the first msg away.
What I want is that the join will create an array with the latest msg received from both flows. So, only create an array when index = 0 and index = 1 are arrived in the join node.
A small example. Two injections called Top and Bottom with msg.payload “Top” and “Bottom”. These will go to a join via change node that msg.parst.id, .count, and .index. And in the end debug node for msg.payload.
When I press bottom twice ther array [null, “Bottom”] is created.
When I press after that twice top an array [‘Top’] (no null) is created.
When I press Top and then Bottom, I have the perfect array [“Top”, “Bottom”].
I hope someone can help me.
[{"id":"f89328c7.f1a65","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"99c04129.058e1","type":"inject","z":"f89328c7.f1a65","name":"","topic":"test","payload":"Top","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":160,"wires":[["74fb3e5a.6df3b"]]},{"id":"188f0069.4763f8","type":"join","z":"f89328c7.f1a65","name":"","mode":"auto","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":730,"y":200,"wires":[["3fd7a07b.ac1fd8"]]},{"id":"3fd7a07b.ac1fd8","type":"debug","z":"f89328c7.f1a65","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":200,"wires":[]},{"id":"74fb3e5a.6df3b","type":"change","z":"f89328c7.f1a65","name":"","rules":[{"t":"set","p":"parts.index","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"parts.count","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"parts.id","pt":"msg","to":"55aa","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":160,"wires":[["188f0069.4763f8"]]},{"id":"e0843b9c.d3484","type":"change","z":"f89328c7.f1a65","name":"","rules":[{"t":"set","p":"parts.index","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"parts.count","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"parts.id","pt":"msg","to":"55aa","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":240,"wires":[["188f0069.4763f8"]]},{"id":"89d249c6.8c383","type":"inject","z":"f89328c7.f1a65","name":"","topic":"test","payload":"Bottom","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":240,"wires":[["e0843b9c.d3484"]]}]
`