# Function not working after update

**URL:** <https://discourse.nodered.org/t/function-not-working-after-update/6964>\
**Category:** General\
**Created:** [18 January 2019 12:58 UTC](https://discourse.nodered.org/t/function-not-working-after-update/6964 "2019-01-18T12:58:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [18 January 2019 12:58 UTC](https://discourse.nodered.org/t/function-not-working-after-update/6964/1 "2019-01-18T12:58:38Z")

</div>

Good afternoon

I have a function tat takes the msg.payload with 2 different topics and returns me the diference ont he value.

Previously was working fine but after updating node red now returns me "NAN".

Function is:

if (msg.topic == "/ESP-6/DHT sala/Temperature") {  
context.state = msg.payload;

}  
if (msg.topic == "/ESP-7/BME280/Temperature") {  
context.state2 = msg.payload;

}

temp = (context.state2-context.state);

[//msg.payload](https://msg.payload) = parseFloat(temp).toFixed(1);  
msg.payload = temp;

return msg;

Do you have some clue what is wrong or why now does not works while previously it was fine?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [18 January 2019 13:05 UTC](https://discourse.nodered.org/t/function-not-working-after-update/6964/2 "2019-01-18T13:05:16Z")

</div>

NAN = not a number so check what the values actually are with some logging messages  
[https://nodered.org/docs/writing-functions#logging-events](https://nodered.org/docs/writing-functions#logging-events)

Whilst you are on that page you could carry on reading the part about how to store data which changed a while ago. Given you are editing the function node it you might as well edit that as well 🙂  
[https://nodered.org/docs/writing-functions#storing-data](https://nodered.org/docs/writing-functions#storing-data)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [18 January 2019 14:16 UTC](https://discourse.nodered.org/t/function-not-working-after-update/6964/3 "2019-01-18T14:16:50Z")

</div>

And also please read this post on sharing code/flows in the forum. It takes just a second to format your code on the forum and it makes it a lot easier for use to read.

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [18 January 2019 20:40 UTC](https://discourse.nodered.org/t/function-not-working-after-update/6964/4 "2019-01-18T20:40:59Z")

</div>

I will remake my question.... Do you have any example on a function to make the addition of 2 values received with different topics?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 January 2019 22:06 UTC](https://discourse.nodered.org/t/function-not-working-after-update/6964/5 "2019-01-18T22:06:33Z")

</div>

> [@davidcgu](#):
>
> Do you have any example on a function to make the addition of 2 values received with different topics?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/336a8a27135d3d6cfce288496f5946c7eede4cd2.png)

```auto
[{"id":"88596265.43ade8","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"topicA","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":104.5,"y":149,"wires":[["276ef579.9944d2"]]},{"id":"276ef579.9944d2","type":"join","z":"514a90a5.c7bae8","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":281.5,"y":199,"wires":[["6e3d3527.774c9c"]]},{"id":"6d0e421e.c691ac","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"topicB","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":108,"y":252,"wires":[["276ef579.9944d2"]]},{"id":"6e3d3527.774c9c","type":"change","z":"514a90a5.c7bae8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.topicA + payload.topicB","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":454.5,"y":201,"wires":[["b5e86695.593dd8"]]},{"id":"b5e86695.593dd8","type":"debug","z":"514a90a5.c7bae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":519.5,"y":270,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [18 January 2019 23:00 UTC](https://discourse.nodered.org/t/function-not-working-after-update/6964/6 "2019-01-18T23:00:19Z")

</div>

Thanks a lot Colin
