# Saving a msg.payload and than comparing the new msg with same topic later on

**URL:** <https://discourse.nodered.org/t/saving-a-msg-payload-and-than-comparing-the-new-msg-with-same-topic-later-on/67391>\
**Category:** General\
**Created:** [6 September 2022 12:06 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-and-than-comparing-the-new-msg-with-same-topic-later-on/67391 "2022-09-06T12:06:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samokomo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/samokomo/32/63918_2.png) [@Samokomo](https://discourse.nodered.org/u/Samokomo)\
**Post date:** [6 September 2022 12:06 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-and-than-comparing-the-new-msg-with-same-topic-later-on/67391/1 "2022-09-06T12:06:39Z")

</div>

Hello NodeRed community!

I am still kinda NodeRed newbie and I would appriciate some help here.

My situation is:

My messages from devices are identified via msg.topic which equals to mac address of particular device.  
I want to store msg.payload.interface (one of payloads attributes) **latest** value. When new msg with same topic arrives, I need to compare its interface value with stored (latest) value.

Basically I need to evaluate if msg.payload.interface has changed for same topic. Any tips how to do this in steamless fashion?

Thanks!

---

<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:** [6 September 2022 12:34 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-and-than-comparing-the-new-msg-with-same-topic-later-on/67391/2 "2022-09-06T12:34:17Z")

</div>

The Filter/RBE node can be set to handle multiple topics - so if the payload isn't too complicated it can probably handle it... but if any other values of the payload change then you would need to do an extra step - eg use a change node to set msg.interface to msg.payload.interface and then send to the filter and test msg.interface.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 September 2022 12:38 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-and-than-comparing-the-new-msg-with-same-topic-later-on/67391/3 "2022-09-06T12:38:20Z")

</div>

Or you can store the value you wish in a context var, then compare then store new to context.  
e.g.

```auto
[{"id":"5fd04de4.af31e4","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"1234","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","x":80,"y":1020,"wires":[["10adbeec.549b39"]]},{"id":"10adbeec.549b39","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"previous","pt":"msg","to":"interface[msg.topic]","tot":"flow"},{"t":"set","p":"output","pt":"msg","to":"$$.previous = $$.payload.interface","tot":"jsonata"},{"t":"set","p":"interface[msg.topic]","pt":"flow","to":"payload.interface","tot":"msg"},{"t":"move","p":"output","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1100,"wires":[["8384a06e.08c0f"]]},{"id":"65d3e2b3.f75f44","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"12345","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","x":90,"y":1080,"wires":[["10adbeec.549b39"]]},{"id":"6a3a8b54.81785c","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"1234","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","x":70,"y":1140,"wires":[["10adbeec.549b39"]]},{"id":"2200c8aa.6da738","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"1235","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","x":70,"y":1180,"wires":[["10adbeec.549b39"]]},{"id":"8384a06e.08c0f","type":"debug","z":"30af2d3e.d94ea2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":1120,"wires":[]}]

```

---

<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:** [5 November 2022 12:38 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-and-than-comparing-the-new-msg-with-same-topic-later-on/67391/4 "2022-11-05T12:38:30Z")

</div>

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