Help with how to use flow.variables in change node

To try and help, here is a basic flow which is what I am needing to do elsewhere with other things.

I have two flow.context values.
I want to multiply them and send that out as the payload.

eg: flow.number and flow.multiplier

How do I make the payload of the change node equal flow.number * flow.multiplier?

[{"id":"c1f60fd3.ccbba","type":"inject","z":"68e3655f.b606b4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":2340,"wires":[["837a3ff3.4f35c"]]},{"id":"837a3ff3.4f35c","type":"change","z":"68e3655f.b606b4","name":"","rules":[{"t":"set","p":"something","pt":"flow","to":"20","tot":"num"},{"t":"set","p":"multiplier","pt":"flow","to":"4","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2340,"wires":[[]]},{"id":"aee3facd.6eef78","type":"change","z":"68e3655f.b606b4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{{flow.something}} * {{flow.multiplier}}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":2390,"wires":[["9dc17d14.4ff7b"]]},{"id":"6c976108.74a12","type":"inject","z":"68e3655f.b606b4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":2390,"wires":[["aee3facd.6eef78"]]},{"id":"9dc17d14.4ff7b","type":"debug","z":"68e3655f.b606b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":570,"y":2390,"wires":[]}]

Hi Andrew,

The simplest way for me was to use a function node .. but i made a jsonata example also in the flow

[{"id":"5f453cca.a3ecac","type":"inject","z":"fda56582.991c78","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":260,"wires":[["dd15a62d.ad3ef"]]},{"id":"dd15a62d.ad3ef","type":"change","z":"fda56582.991c78","name":"","rules":[{"t":"set","p":"something","pt":"flow","to":"20","tot":"num"},{"t":"set","p":"multiplier","pt":"flow","to":"4","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":260,"wires":[[]]},{"id":"eada785a.765b6","type":"inject","z":"fda56582.991c78","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":340,"wires":[["73c3f63f.22791"]]},{"id":"81986b68.59ff58","type":"debug","z":"fda56582.991c78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":710,"y":340,"wires":[]},{"id":"73c3f63f.22791","type":"function","z":"fda56582.991c78","name":"","func":"let something = flow.get('something')\nlet multiplier = flow.get('multiplier')\n\nmsg.payload = something * multiplier\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":340,"wires":[["81986b68.59ff58"]]},{"id":"65b02741.d1614","type":"change","z":"fda56582.991c78","name":"jsonata","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext('something') * $flowContext('multiplier')\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":440,"wires":[["bff9d42a.ca119"]]},{"id":"f5a99dbd.b1c4f8","type":"inject","z":"fda56582.991c78","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":440,"wires":[["65b02741.d1614"]]},{"id":"bff9d42a.ca119","type":"debug","z":"fda56582.991c78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":730,"y":440,"wires":[]}]
1 Like

Thanks.

I only did it the way I did because I am trying to wean myself off using function nodes and use change nodes.

I like functions. they give you the full power of javascript
for example if you wanted to do some check whether the values are actually set in context before multiplying them.
but jsonata in a change node is very powerful also .. which im trying to learn :wink:

I do agree, but there is a part of me asking about the overhead of a function node compared to a change node.

But, I guess with the stuff I do, that is splitting hairs.
(ie: I don't really code well.)

You can use:

$flowContext("something")*$flowContext("multiplier")

as jsonata expression

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