# Separate out different messages

**URL:** <https://discourse.nodered.org/t/separate-out-different-messages/81426>\
**Category:** General\
**Tags:** function-node\
**Created:** [18 September 2023 19:11 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426 "2023-09-18T19:11:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![garthpaine](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/garthpaine/32/83004_2.png) [@garthpaine](https://discourse.nodered.org/u/garthpaine)\
**Post date:** [18 September 2023 19:11 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426/1 "2023-09-18T19:11:18Z")

</div>

I want to know when I get a LoRA Join message rather than other data packets - so for instance the following is a join message - I want to separate out these from other messages - but trying to look for instance ---

```js
if (msg.payload.join_accept.session_key_id){
                   // do nothing 
 } else if (msg.payload.uplink_message.decoded_payload.Cert > 0){

```

does not work as the `msg.payload.join_accept.session_key_id` does not exist in other messages - would love some thoughts - thanks, Garth

```auto
{"end_device_ids":{"device_id":"18-audio","application_ids":{"application_id":"costa-rica-development"},"dev_eui":"xxxxxxxxxx","join_eui":"xxxxxxx","dev_addr":"xxxxxxx"},"correlation_ids":["as:up:xxxxxxxx","gs:conn:xxxxxxx","gs:up:host:xxxxxxxk:xxxxxxx","ns:uplink:xxxxxxx","rpc:/ttn.lorawan.v3.GsNs/HandleUplink:xxxxxxx","rpc:/ttn.lorawan.v3.NsAs/HandleUplink:xxxxxxx"],"received_at":"2023-09-18T19:04:27.003981894Z","join_accept":{"session_key_id":"xxxxxxxxxx==","received_at":"2023-09-18T19:04:xxxxxxxx'

```

* * *

_Admin edit: wrap code in backticks_

---

<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:** [18 September 2023 19:22 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426/2 "2023-09-18T19:22:02Z")

</div>

You can use a switch mode to direct messages by adding 2 entries

1. Has key : `msg.payload.join_accept.session_key_id`
2. Otherwise

Then you don't need to worry about testing for the existence of the key at all

---

<div class="post-metadata">

**Author:** ![garthpaine](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/garthpaine/32/83004_2.png) [@garthpaine](https://discourse.nodered.org/u/garthpaine)\
**Post date:** [18 September 2023 19:43 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426/3 "2023-09-18T19:43:08Z")

</div>

Thanks so much Steve

how do you recommend implementing this as an if statement throws an error if that part of the payload is not present - indeed a Switch statement would be a great approach

---

<div class="post-metadata">

**Author:** ![garthpaine](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/garthpaine/32/83004_2.png) [@garthpaine](https://discourse.nodered.org/u/garthpaine)\
**Post date:** [18 September 2023 19:46 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426/4 "2023-09-18T19:46:11Z")

</div>

actually I got it - thanks Genius!!

---

<div class="post-metadata">

**Author:** ![garthpaine](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/garthpaine/32/83004_2.png) [@garthpaine](https://discourse.nodered.org/u/garthpaine)\
**Post date:** [19 September 2023 17:21 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426/5 "2023-09-19T17:21:57Z")

</div>

OK I'm back

so this works msg.payload.join\_accept and catches all Join requests which is great  
However if I try

1. Has key : uplink\_message.decoded\_payload.Cert

I do not get a match, even though this exists in the alternative uploaded message.  
Any advice would be welcome - thanks

---

<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:** [19 September 2023 20:13 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426/6 "2023-09-19T20:13:58Z")

</div>

Show us the incoming message copied from the debug pane using Copy Value in the debug pane, and also screenshot of how you have setup the Switch node.

---

<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:** [18 November 2023 20:14 UTC](https://discourse.nodered.org/t/separate-out-different-messages/81426/7 "2023-11-18T20:14:03Z")

</div>

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