# Adding a payload to a varible

**URL:** <https://discourse.nodered.org/t/adding-a-payload-to-a-varible/28939>\
**Category:** General\
**Created:** [25 June 2020 07:12 UTC](https://discourse.nodered.org/t/adding-a-payload-to-a-varible/28939 "2020-06-25T07:12:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmystique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rmystique/32/84365_2.png) [@rmystique](https://discourse.nodered.org/u/rmystique)\
**Post date:** [25 June 2020 07:12 UTC](https://discourse.nodered.org/t/adding-a-payload-to-a-varible/28939/1 "2020-06-25T07:12:04Z")

</div>

I am trying to take an input payload and add to it a varible that is stored and output a combined value using a function node with the following:

msg.payload = msg.payload + flow.delay  
return msg;

But i get a debug output of "NaN"

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 June 2020 07:21 UTC](https://discourse.nodered.org/t/adding-a-payload-to-a-varible/28939/2 "2020-06-25T07:21:02Z")

</div>

One of those values must not be a number, maybe its a string that looks like a number ? We can't tell from the information given. You'll have to add debug to show us the values it is trying to add.

---

<div class="post-metadata">

**Author:** ![rmystique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rmystique/32/84365_2.png) [@rmystique](https://discourse.nodered.org/u/rmystique)\
**Post date:** [26 June 2020 06:06 UTC](https://discourse.nodered.org/t/adding-a-payload-to-a-varible/28939/3 "2020-06-26T06:06:04Z")

</div>

Here is what I have, the problemis the "add" function node, it can't seem to get the flow.delay varible to add that is set in the top flow, if you change both numeric inputs the you should get a new value that combine them in th edebug on the "add" function node:

```auto
[{"id":"4f215bbb.29d7f4","type":"function","z":"4f2cae6a.c5ec8","name":"add","func":"msg.payload = msg.payload + (flow.delay/1000)\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":480,"wires":[["abbcbdc2.d3d13","9d49a70f.862808"]]},{"id":"eb8e781f.3f2548","type":"inject","z":"4f2cae6a.c5ec8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"3","x":90,"y":440,"wires":[["fdff23af.dcc9","a1b34093.96a85"]]},{"id":"fdff23af.dcc9","type":"file in","z":"4f2cae6a.c5ec8","name":"load delay","filename":"water_delay","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":250,"y":440,"wires":[["cde19d5b.bf893"]]},{"id":"a1b34093.96a85","type":"file in","z":"4f2cae6a.c5ec8","name":"load interval","filename":"water_interval","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":250,"y":480,"wires":[["484e3ba1.aa4e54"]]},{"id":"cde19d5b.bf893","type":"ui_numeric","z":"4f2cae6a.c5ec8","name":"Water time","label":"Water time (mins)","tooltip":"","group":"a92077cf.7a28e8","order":5,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"","format":"{{value}}","min":"1","max":"15","step":1,"x":410,"y":440,"wires":[["f59c944f.33db88"]]},{"id":"484e3ba1.aa4e54","type":"ui_numeric","z":"4f2cae6a.c5ec8","name":"","label":"Water interval","tooltip":"","group":"a92077cf.7a28e8","order":4,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"","format":"{{value}}","min":"0","max":"720","step":"5","x":420,"y":480,"wires":[["68f823d7.50888c"]]},{"id":"f59c944f.33db88","type":"file","z":"4f2cae6a.c5ec8","name":"Save delay","filename":"water_delay","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":570,"y":440,"wires":[["c75e159.7e557e8"]]},{"id":"68f823d7.50888c","type":"file","z":"4f2cae6a.c5ec8","name":"save interval","filename":"water_interval","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":590,"y":480,"wires":[["4f215bbb.29d7f4"]]},{"id":"c75e159.7e557e8","type":"function","z":"4f2cae6a.c5ec8","name":"Multiplier","func":"msg.payload = msg.payload *1000\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":440,"wires":[["6eadcd45.8a6574"]]},{"id":"abbcbdc2.d3d13","type":"debug","z":"4f2cae6a.c5ec8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":750,"y":380,"wires":[]},{"id":"6eadcd45.8a6574","type":"change","z":"4f2cae6a.c5ec8","name":"","rules":[{"t":"set","p":"delay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":440,"wires":[["6f96ee9e.484cd"]]},{"id":"9d49a70f.862808","type":"change","z":"4f2cae6a.c5ec8","name":"","rules":[{"t":"set","p":"delay1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":480,"wires":[["3b11b096.22ec5"]]},{"id":"6f96ee9e.484cd","type":"debug","z":"4f2cae6a.c5ec8","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1170,"y":440,"wires":[]},{"id":"3b11b096.22ec5","type":"debug","z":"4f2cae6a.c5ec8","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1170,"y":500,"wires":[]},{"id":"a92077cf.7a28e8","type":"ui_group","z":"","name":"#1","tab":"7dd97b74.960734","order":2,"disp":true,"width":"6","collapse":false},{"id":"7dd97b74.960734","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 June 2020 07:46 UTC](https://discourse.nodered.org/t/adding-a-payload-to-a-varible/28939/4 "2020-06-26T07:46:01Z")

</div>

That isn't how you retrieve flow context variables in a function - see the Storing data section of the docs [https://nodered.org/docs/user-guide/writing-functions#Storing-data](https://nodered.org/docs/user-guide/writing-functions#Storing-data)

hint `flow.get("delay")`

---

<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:** [10 July 2020 07:46 UTC](https://discourse.nodered.org/t/adding-a-payload-to-a-varible/28939/5 "2020-07-10T07:46:06Z")

</div>

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