# Send Message only if it is the Same as before

**URL:** <https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511>\
**Category:** General\
**Created:** [23 June 2019 16:04 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511 "2019-06-23T16:04:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMO\_the\_Console](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@BMO\_the\_Console](https://discourse.nodered.org/u/BMO_the_Console)\
**Post date:** [23 June 2019 16:04 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/1 "2019-06-23T16:04:39Z")

</div>

Hello,

i would like to forward a Massage to the next Node, but only if the Message is the Same Message as befor.

Best Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 June 2019 16:23 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/2 "2019-06-23T16:23:26Z")

</div>

What qualifies the message as being the same? The contents of payload? The string in topic? Both? All properties of `msg`?

A simple way would be to use a function node, get/set last value in node context, if same, `return msg` if different, `return null`

Note, once node context is set, you can only ever get that same message through forever more. Seems like an odd request?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [23 June 2019 17:37 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/3 "2019-06-23T17:37:19Z")

</div>

You need the opposite of the RBE node (report by equality?). As @Steve-Mcl said, using node context is the way to go in a function node. Give it a try, you will learn a lot about the workings of node red. If you get stuck just ask!

---

<div class="post-metadata">

**Author:** ![moebius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moebius/32/2872_2.png) [@moebius](https://discourse.nodered.org/u/moebius)\
**Post date:** [23 June 2019 18:05 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/4 "2019-06-23T18:05:35Z")

</div>

Right, the switch node is the way to go...you will achieve your goal without a single line of coding 🙂

![Screenshot%20at%202019-06-23%2020-03-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d69fa5a08ea2a5cc1f6e3071162d588aaf7fadb1.png)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [23 June 2019 18:11 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/5 "2019-06-23T18:11:15Z")

</div>

Ah, of course. Brilliant!

---

<div class="post-metadata">

**Author:** ![BMO\_the\_Console](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@BMO\_the\_Console](https://discourse.nodered.org/u/BMO_the_Console)\
**Post date:** [23 June 2019 18:32 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/6 "2019-06-23T18:32:10Z")

</div>

Thanks, i will try this.

---

<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:** [23 June 2019 19:00 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/7 "2019-06-23T19:00:37Z")

</div>

That only works if you want msg.payload to be the same as before.

As @Steve-Mcl already suggested it depends on if you just want msg.payload to be the same or the entire message as you initially stated

---

<div class="post-metadata">

**Author:** ![BMO\_the\_Console](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@BMO\_the\_Console](https://discourse.nodered.org/u/BMO_the_Console)\
**Post date:** [23 June 2019 19:12 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/8 "2019-06-23T19:12:31Z")

</div>

msg.payload is fine, so the switch Node Methode should work. Will try when i get Home.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [23 June 2019 20:03 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/9 "2019-06-23T20:03:29Z")

</div>

The entire message will always be different because of the \_msgid.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 June 2019 20:41 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/10 "2019-06-23T20:41:06Z")

</div>

Of course, I/we did mean all properties that the user added to the message i.e. more than just payload. 😄

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [24 June 2019 07:48 UTC](https://discourse.nodered.org/t/send-message-only-if-it-is-the-same-as-before/12511/11 "2019-06-24T07:48:11Z")

</div>

\<pedantic\_mode\_off\> 🙂
