# Any way of effectively swapping the outputs

**URL:** <https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791>\
**Category:** General\
**Created:** [17 May 2020 10:42 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791 "2020-05-17T10:42:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [17 May 2020 10:42 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/1 "2020-05-17T10:42:28Z")

</div>

I believe the answer is no but I'd thought I'd ask as there is no "doesn't contain" option in the switch node

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

Would just help in tidying up wires - not critical issue 🙂

[edit]Maybe some simple JSONAta?[/edit]

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 May 2020 10:54 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/2 "2020-05-17T10:54:32Z")

</div>

Could you not use a regex?

---

<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:** [17 May 2020 10:59 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/3 "2020-05-17T10:59:55Z")

</div>

Try this example flow the jsonata is `$contains(payload, "simon says")!= true`

```auto
[{"id":"1814bb4.c8873c5","type":"switch","z":"cb9367c5.85f7e8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"$contains(payload, \"simon says\")!= true","vt":"jsonata"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":520,"wires":[["88cd6414.436a6"],["c2c17797.73541"]]},{"id":"411905fc.24a224","type":"inject","z":"cb9367c5.85f7e8","name":"","topic":"","payload":"foo","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":460,"wires":[["1814bb4.c8873c5"]]},{"id":"f604288b.6b21d","type":"inject","z":"cb9367c5.85f7e8","name":"simon says","topic":"","payload":"well simon says I'm good","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":560,"wires":[["1814bb4.c8873c5"]]},{"id":"88cd6414.436a6","type":"debug","z":"cb9367c5.85f7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":480,"y":460,"wires":[]},{"id":"c2c17797.73541","type":"debug","z":"cb9367c5.85f7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":560,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [17 May 2020 11:00 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/4 "2020-05-17T11:00:57Z")

</div>

JSONata:

```auto
$not($contains(payload, 'simon says'))	

```

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [17 May 2020 11:01 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/5 "2020-05-17T11:01:03Z")

</div>

I usually avoid RegEx if possible

But I'm sure it would work - can you supply the magic incantation?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [17 May 2020 11:06 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/6 "2020-05-17T11:06:02Z")

</div>

> [@cflurin](#):
>
> $not($contains(payload, 'simon says'))

Thanks @cflurin and @zenofmud - I gave solution to @cflurin as marginally shorter 🙂

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 May 2020 11:41 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/8 "2020-05-17T11:41:11Z")

</div>

Off the Top of my head `(?!.*(simon says)).*$`

---

<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:** [17 May 2020 13:07 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/9 "2020-05-17T13:07:56Z")

</div>

> [@cymplecy](#):
>
> I gave solution to @cflurin as marginally shorter

I would to, I didn't see the `$not` or would have used it also. But I should get bonus points for providing a flow! 🤣

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [17 May 2020 13:22 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/10 "2020-05-17T13:22:11Z")

</div>

BTW - use contain a lot (in my Alexa parsing flows) so this technique will be quite useful for me 🙂

And even I can understand the JSONata used 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [31 May 2020 13:34 UTC](https://discourse.nodered.org/t/any-way-of-effectively-swapping-the-outputs/26791/11 "2020-05-31T13:34:57Z")

</div>

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