# Compare 2 payloads with function node

**URL:** <https://discourse.nodered.org/t/compare-2-payloads-with-function-node/42174>\
**Category:** General\
**Created:** [6 March 2021 22:03 UTC](https://discourse.nodered.org/t/compare-2-payloads-with-function-node/42174 "2021-03-06T22:03:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfedo](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sfedo](https://discourse.nodered.org/u/sfedo)\
**Post date:** [6 March 2021 22:03 UTC](https://discourse.nodered.org/t/compare-2-payloads-with-function-node/42174/1 "2021-03-06T22:03:34Z")

</div>

Hello,  
I'm struggling with a function.  
I have 2 payloads. Let's name them msg.payload.1 and msg.payload.2.

Now the function:

```auto
if (msg.payload.1==true && msg.payload.2==true){
msg.payload=false;
}else{
msg.payload=true;
}
return msg;

```

I cannot compare 2 undepended nodes without storing at least one of them inside context, right?  
Or is there a way to do this?

---

<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:** [6 March 2021 22:31 UTC](https://discourse.nodered.org/t/compare-2-payloads-with-function-node/42174/2 "2021-03-06T22:31:53Z")

</div>

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<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:** [7 March 2021 07:23 UTC](https://discourse.nodered.org/t/compare-2-payloads-with-function-node/42174/3 "2021-03-07T07:23:35Z")

</div>

Or use one of the logic nodes, I use node-red-contrib-bool-gate

---

<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:** [6 May 2021 07:23 UTC](https://discourse.nodered.org/t/compare-2-payloads-with-function-node/42174/4 "2021-05-06T07:23:38Z")

</div>

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