# Getting payload data from function to two debug nodes

**URL:** <https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895>\
**Category:** General\
**Created:** [19 May 2021 08:59 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895 "2021-05-19T08:59:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpbillund](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tpbillund/32/37410_2.png) [@tpbillund](https://discourse.nodered.org/u/tpbillund)\
**Post date:** [19 May 2021 08:59 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/1 "2021-05-19T08:59:14Z")

</div>

Hi.

I am trying to get data from two nodes to debug nodes, by a function.  
If I add a debug node to the two nodes (zigbee nodes) I get this data.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e283f0d0fed128d824230a998e055111fd202815.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8f7bc96e0072e8ce6adb73433343e38a23d2b676.png)

I am then trying to get the payload data by a function and if the:  
contact is "false" then it need to send the payload data to one debug node  
occupancy is "true" it need to send the payload data to another debug node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/1882017fce31f83e4a6dffe5aab5cbd0127a4fc5.png)

But I get no data from the function.

My function code is (on message):

```auto
node.status({fill:"green",shape:"ring",text:"done"});
var contact = msg.payload.contact;
var occupancy = msg.payload.occupancy;

if (contact == "false"){
    return [msg,null];  
}
if (occupancy == "true"){
    return [msg,null];    
}

```

---

<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:** [19 May 2021 09:02 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/2 "2021-05-19T09:02:20Z")

</div>

`contact` is boolean not a string.

so this should work.

```auto
if (contact == false){
    return [msg,null];  
} 

```

NOTE: you could use a simple switch node to do this.

---

<div class="post-metadata">

**Author:** ![tpbillund](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tpbillund/32/37410_2.png) [@tpbillund](https://discourse.nodered.org/u/tpbillund)\
**Post date:** [19 May 2021 09:11 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/3 "2021-05-19T09:11:31Z")

</div>

Hi @Steve-Mcl THX.  
"the needle in the haystack"

I started with a switch node... but how can i get the switch node to look on both msg.payload.contact;  
and msg.payload.occupancy?

---

<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:** [19 May 2021 09:20 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/4 "2021-05-19T09:20:19Z")

</div>

You can use 2 switch nodes  
sw1 - contact == false OR otherwise  
sw2 - occupancy == true or otherwise

or you can do it with e switch node and a JSONata expression  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04a8ba5343036cdcd710d78bd05880f1bf6d9c96.png)

expression: `payload.contact = false ? 1 : (payload.occupancy = true ? 2 : 0)`

but, the function node is sometimes the best solution.

---

<div class="post-metadata">

**Author:** ![tpbillund](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tpbillund/32/37410_2.png) [@tpbillund](https://discourse.nodered.org/u/tpbillund)\
**Post date:** [19 May 2021 09:23 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/5 "2021-05-19T09:23:57Z")

</div>

Ok thx.

> ...the function node is sometimes the best solution.  
> Ok atm. it use the same output (top) to one debug node, for contact and occupancy, the occupancy is not using the other debug node.. hmm

---

<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:** [19 May 2021 09:25 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/6 "2021-05-19T09:25:44Z")

</div>

> [@tpbillund](#):
>
> atm. it use the same output (top) to one debug node, for contact and occupancy, the occupancy is not using the other debug node.. hmm

because the 2nd `return` needs a different signature...

```javascript
if (occupancy == true){
    //return [msg, null]; //<< output to pin 1
    return [null, msg]; //<< output to pin 2
}

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [19 May 2021 09:32 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/7 "2021-05-19T09:32:47Z")

</div>

Doesn't this work in a switch node.

![jsonata](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d186b5a679f7505fb25cb9a4e99fef2ed8c3dc1d.jpeg)

---

<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:** [2 June 2021 10:03 UTC](https://discourse.nodered.org/t/getting-payload-data-from-function-to-two-debug-nodes/45895/9 "2021-06-02T10:03:30Z")

</div>

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