# Yet another "strange" behavior of the switch node

**URL:** <https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107>\
**Category:** General\
**Created:** [3 May 2022 09:47 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107 "2022-05-03T09:47:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniele-Tampieri](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daniele-tampieri/32/40688_2.png) [@Daniele-Tampieri](https://discourse.nodered.org/u/Daniele-Tampieri)\
**Post date:** [3 May 2022 09:47 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/1 "2022-05-03T09:47:58Z")

</div>

First of all, some contextual info  
**OS** : Linux RevPi34798 4.19.95-rt38-v7.  
**Dashboard version** : v1.35.

**The problem**. I am designing a flow where a given message payload of the form

```auto
{
"section_1":{"CEV" : 0, "s" : 2},
"section_2":{"CEV" : 1, "s" : 3},
"section_n":{"CEV" : 0, "s" : 1}
}

```

(`n` stands for a generic number of sections, and can be just 1) is first split with a standard (dashboard) `split` node in parts whose `msg.payload` have the following form:

```auto
{"CEV":0, "s":2}

```

These parts are then split again in messages whose payload are their simple numerical values: here it comes the problem. I want to route these values by using a `switch` node according to their `msg.part.key` value (respectively `CEV` and `s`): however, this does not work.   
 For example, in the 1-section model flow below

 ![Schermata 2022-05-03 alle 09.31.21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fbc29bb6e6e1cf904adf0318bb8be30091573ae0.png)  
where the `inject` node `sec_sts` injects the following complete message (copied from the preceding `switch` node in the full flow)

```auto
{
"_msgid":"bd05ad6a.fcb66",
"payload":{"CEV":0,"s":2},
"topic":"section_1",
"_event":"node:d7590ba5.b163f8",
"parts": {
         "id":"7e6805a9.7a7c4c",
         "type":"object",
         "key":"section_1",
         "index":0,
         "count":1}
}

```

and the `split` node works perfectly giving the following two complete messages

```auto
{
"payload":0,
"topic":"section_1",
"_event":"node:d7590ba5.b163f8",
"parts":{
        "parts":{
                 "id":"7e6805a9.7a7c4c",
                 "type":"object",
                 "key":"section_1",
                 "index":0,
                 "count":1
                 },
        "id":"6cb0f9b3.45c048",
        "type":"object",
        "key":"CEV",
        "index":0,
        "count":2
        },
"_msgid":"8dd99f88.82b48"
}

```

and

```auto
{
"payload":2,
"topic":"section_1",
"_event":"node:d7590ba5.b163f8",
"parts":{
        "parts":{
                "id":"7e6805a9.7a7c4c",
                "type":"object",
                "key":"section_1",
                "index":0,"count":1
                },
        "id":"6cb0f9b3.45c048",
        "type":"object",
        "key":"s",
        "index":1,
        "count":2
        },
"_msgid":"3e32f1bf.799b2e"
}

```

I am not able to make the `sts_router` `split` node work correctly, i.e. to make it work according to the values of the `msg.parts.key` property. Setting of the `sts_router` node is

 ![Schermata 2022-05-03 alle 11.45.59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e2e8fd56cdf9e40388f1122cb15c4ea5e6a1f53.png)  
I'm almost sure that I am missing something trivial, but I am not able to see it, so I've decided to ask for your precious help. Thanks in advance.

---

<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:** [3 May 2022 11:12 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/2 "2022-05-03T11:12:20Z")

</div>

> [@Daniele-Tampieri](#):
>
> For example, in the 1-section model flow below
> 
> ![Schermata 2022-05-03 alle 09.31.21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fbc29bb6e6e1cf904adf0318bb8be30091573ae0.png)

Can you share this flow?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 May 2022 11:22 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/3 "2022-05-03T11:22:42Z")

</div>

It seems to work for me:

 ![Untitled 4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/8791c2ff61f7d02db9d8da8b3502e39f3cd6a4c4.jpeg)

```auto
[{"id":"985a0f35b471ede0","type":"inject","z":"b5d64c1e024cd3e1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":80,"wires":[["11070a651fa11b17"]]},{"id":"11070a651fa11b17","type":"function","z":"b5d64c1e024cd3e1","name":"","func":"msg = {\n \"_msgid\": \"bd05ad6a.fcb66\",\n \"payload\": { \"CEV\": 0, \"s\": 2 },\n \"topic\": \"section_1\",\n \"_event\": \"node:d7590ba5.b163f8\",\n \"parts\": {\n \"id\": \"7e6805a9.7a7c4c\",\n \"type\": \"object\",\n \"key\": \"section_1\",\n \"index\": 0,\n \"count\": 1\n }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":80,"wires":[["5aa06001df5f592f","1337022978ff3031"]]},{"id":"5aa06001df5f592f","type":"split","z":"b5d64c1e024cd3e1","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":390,"y":80,"wires":[["dd5fe6d32c4004aa","789e98ce129cb03b"]]},{"id":"1337022978ff3031","type":"debug","z":"b5d64c1e024cd3e1","name":"injected data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":370,"y":140,"wires":[]},{"id":"dd5fe6d32c4004aa","type":"switch","z":"b5d64c1e024cd3e1","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"s","vt":"str"},{"t":"eq","v":"CEV","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":570,"y":80,"wires":[["5f3ddd60801eed9d"],["27bd395092ec0d30"],["a9766439d28fd31e"]]},{"id":"5f3ddd60801eed9d","type":"debug","z":"b5d64c1e024cd3e1","name":"key = s","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":40,"wires":[]},{"id":"27bd395092ec0d30","type":"debug","z":"b5d64c1e024cd3e1","name":"key = CEV","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":80,"wires":[]},{"id":"a9766439d28fd31e","type":"debug","z":"b5d64c1e024cd3e1","name":"otherwise","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":140,"wires":[]},{"id":"789e98ce129cb03b","type":"debug","z":"b5d64c1e024cd3e1","name":"split data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 May 2022 11:25 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/4 "2022-05-03T11:25:23Z")

</div>

> [@Daniele-Tampieri](#):
>
> ```auto
> {
> "payload":2,
> "topic":"section_1",
> "_event":"node:d7590ba5.b163f8",
> "parts":{
> "parts":{
> "id":"7e6805a9.7a7c4c",
> "type":"object",
> "key":"section_1",
> "index":0,"count":1
> },
> 
> ```

Shouldn’t you be testing msg.parts.parts.key?

---

<div class="post-metadata">

**Author:** ![Daniele-Tampieri](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daniele-tampieri/32/40688_2.png) [@Daniele-Tampieri](https://discourse.nodered.org/u/Daniele-Tampieri)\
**Post date:** [3 May 2022 12:35 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/5 "2022-05-03T12:35:52Z")

</div>

Sure, here it is.  
[flows-3.json](https://discourse.nodered.org/uploads/short-url/37v57DYnCQ6foZIk0mYCieP535V.json) (4.0 KB)

---

<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:** [3 May 2022 12:40 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/6 "2022-05-03T12:40:26Z")

</div>

I dont see any issue other than you had turned off the debug node output. Here is your flow with separate debug nodes and output and status enabled....

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c23c190fb19d8d1c9985e2b59dc01904efa9dad.png)

---

<div class="post-metadata">

**Author:** ![Daniele-Tampieri](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daniele-tampieri/32/40688_2.png) [@Daniele-Tampieri](https://discourse.nodered.org/u/Daniele-Tampieri)\
**Post date:** [3 May 2022 12:40 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/7 "2022-05-03T12:40:42Z")

</div>

No, I need to access the outer `msg.parts.key` which correspond to the latest split. Testing `msg.parts.parts` would be equivalent to extract the value of `section_x`, which is the same for `CEV` and `s`.

---

<div class="post-metadata">

**Author:** ![Daniele-Tampieri](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daniele-tampieri/32/40688_2.png) [@Daniele-Tampieri](https://discourse.nodered.org/u/Daniele-Tampieri)\
**Post date:** [3 May 2022 12:44 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/8 "2022-05-03T12:44:47Z")

</div>

You're right: it seems it is an issue of the `RIC out` node: opening it seem that I lose the graphical enable command, possibly during some edit. I've deleted and readded it, and now it works. Thank you very much

---

<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:** [17 May 2022 12:45 UTC](https://discourse.nodered.org/t/yet-another-strange-behavior-of-the-switch-node/62107/9 "2022-05-17T12:45:38Z")

</div>

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