Multiply 2 payloads after join node

Hi All,

Tried to find the answer for this. I can find how to sum 2 separate message payloads. But how do I multiply them together? See below. I want to multiply 10 by 20.

[{"id":"e1b07ecd.4ceac","type":"change","z":"f4e1027028f8a396","name":"Multiply(payload)","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":300,"wires":[["f9afb265.b11b7"]]}]

Thanks

Gareth

Assuming you set the join node to key/value mode and the topics of the 2 messages are value1 & value2...

Add a function after the join

msg.payload = msg.payload.value1 * msg.payload.value2;
return msg;

See this article in the cookbook for an example of how to join messages into one object.

2 Likes

I don't know where you are getting your msg.payloads... but I put this simple example together using...

image image

image

1 Like

If you joined them as an array
payload[0]*payload[1]

Hi All,

Thank you for your replies. Like all things there is multiple ways of doing things. They all work for me. @E1cid seems to 'fit the bill'.

[{"id":"1dcd267e.52b91a","type":"join","z":"96864f49.e119a","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"payload","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":520,"y":280,"wires":[["a1c21c0b.e5731","e1b07ecd.4ceac"]]},{"id":"3f6885c1.6d431a","type":"inject","z":"96864f49.e119a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":180,"y":260,"wires":[["1dcd267e.52b91a"]]},{"id":"3d36ac8b.602294","type":"inject","z":"96864f49.e119a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":180,"y":340,"wires":[["1dcd267e.52b91a"]]},{"id":"a1c21c0b.e5731","type":"debug","z":"96864f49.e119a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":400,"wires":[]},{"id":"280f8401.a0a70c","type":"debug","z":"96864f49.e119a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1100,"y":280,"wires":[]},{"id":"e1b07ecd.4ceac","type":"change","z":"96864f49.e119a","name":"Multiply(payload)","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]*payload[1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":280,"wires":[["280f8401.a0a70c"]]}]

Cheers

Gareth

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