# Storing Previous Value of msg.payload

**URL:** <https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340>\
**Category:** General\
**Created:** [2 September 2020 10:47 UTC](https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340 "2020-09-02T10:47:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandy](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Sandy](https://discourse.nodered.org/u/Sandy)\
**Post date:** [2 September 2020 10:47 UTC](https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340/1 "2020-09-02T10:47:07Z")

</div>

Hi All  
I am updating the message payload with an interval and at a certain condition, I am stopping the updating by giving ON as String to that function .So, I need the Previous Value that is the previous msg payload. Can anyone know it please share your valuable info.

---

<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:** [2 September 2020 11:02 UTC](https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340/2 "2020-09-02T11:02:41Z")

</div>

You can store the value in the function node's context so that it will be available the next time into the function. See the node red docs on Writing Functions where it is described. In particular you will want to use the functions `context.set()` and `context.get()`

---

<div class="post-metadata">

**Author:** ![Sandy](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Sandy](https://discourse.nodered.org/u/Sandy)\
**Post date:** [2 September 2020 11:42 UTC](https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340/3 "2020-09-02T11:42:58Z")

</div>

Thank you Sir,  
Can I have an example Flow..?

---

<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:** [2 September 2020 12:27 UTC](https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340/4 "2020-09-02T12:27:35Z")

</div>

Have you read and understood the docs?

---

<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:** [2 September 2020 12:56 UTC](https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340/5 "2020-09-02T12:56:47Z")

</div>

A quick Google found this which looks as if it might be helpful.  
[http://www.steves-internet-guide.com/node-red-variables/](http://www.steves-internet-guide.com/node-red-variables/)

---

<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:** [1 November 2020 12:57 UTC](https://discourse.nodered.org/t/storing-previous-value-of-msg-payload/32340/6 "2020-11-01T12:57:02Z")

</div>

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