Join values into array in specific order to make a calculation

Dont use array mode if you want guaranteed order. Use key/value mode.

NOTE: It is always courteous to inlude the full name of any contrib nodes you are using in your demo flow (there are after all 4000+ contrib nodes)

OK, so here is a demo of how you can continue to use the calculator node. It uses the key/value mode of the join node to guarantee values are named and predictable regardless of the order they arrive. Once the payload is set with the values, we convert them to an array using a change node.

The second demo shows how you can avoid this step AND avoid the extra contrib node.

chrome_3rCN1V7O4i

The flow...

[{"id":"2e221b1.51df8e4","type":"inject","z":"9a11d6ef7f86328c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"numerator","payload":"3","payloadType":"num","x":1190,"y":100,"wires":[["9d63e1180abe6daf"]]},{"id":"10bd8f79.53bee9","type":"inject","z":"9a11d6ef7f86328c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"denominator","payload":"10","payloadType":"num","x":1200,"y":140,"wires":[["9d63e1180abe6daf"]]},{"id":"9d63e1180abe6daf","type":"join","z":"9a11d6ef7f86328c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":120,"wires":[["d49ab23df184922e"]]},{"id":"8a73976f9414d377","type":"debug","z":"9a11d6ef7f86328c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1630,"y":180,"wires":[]},{"id":"884d77d6bc170327","type":"calculator","z":"9a11d6ef7f86328c","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"div","constant":"","round":false,"decimals":0,"x":1490,"y":180,"wires":[["8a73976f9414d377"]]},{"id":"d49ab23df184922e","type":"change","z":"9a11d6ef7f86328c","name":"copy num' and den' to array","rules":[{"t":"set","p":"payload","pt":"msg","to":"[payload.numerator, payload.denominator]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1560,"y":120,"wires":[["884d77d6bc170327"]]},{"id":"cde63c53c172712c","type":"inject","z":"9a11d6ef7f86328c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"numerator","payload":"3","payloadType":"num","x":1190,"y":240,"wires":[["41053aaafd46bec0"]]},{"id":"3072bf783ee7514c","type":"inject","z":"9a11d6ef7f86328c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"denominator","payload":"10","payloadType":"num","x":1200,"y":280,"wires":[["41053aaafd46bec0"]]},{"id":"41053aaafd46bec0","type":"join","z":"9a11d6ef7f86328c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":260,"wires":[["ca19b97897c49bc1"]]},{"id":"ca19b97897c49bc1","type":"change","z":"9a11d6ef7f86328c","name":"Divide","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.numerator / payload.denominator","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1490,"y":260,"wires":[["289253c8d71ff355"]]},{"id":"289253c8d71ff355","type":"debug","z":"9a11d6ef7f86328c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1630,"y":260,"wires":[]}]
1 Like