# Help with how to use flow.variables in change node

**URL:** <https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575>\
**Category:** General\
**Created:** [8 September 2020 00:47 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575 "2020-09-08T00:47:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 September 2020 00:47 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575/1 "2020-09-08T00:47:53Z")

</div>

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`?

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 September 2020 01:01 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575/2 "2020-09-08T01:01:28Z")

</div>

Hi Andrew,

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 September 2020 01:08 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575/3 "2020-09-08T01:08:40Z")

</div>

Thanks.

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

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 September 2020 01:19 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575/4 "2020-09-08T01:19:12Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 September 2020 01:20 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575/5 "2020-09-08T01:20:54Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [9 September 2020 18:41 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575/6 "2020-09-09T18:41:45Z")

</div>

You can use:

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

```

as jsonata expression

 ![Screenshot 2020-09-09 at 20.42.01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/379e54ec8fedb88f0ef65e84e4cb94a9ba52a80d.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 September 2020 18:42 UTC](https://discourse.nodered.org/t/help-with-how-to-use-flow-variables-in-change-node/32575/7 "2020-09-23T18:42:00Z")

</div>

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