# Change Node: Default or Else?

**URL:** <https://discourse.nodered.org/t/change-node-default-or-else/30696>\
**Category:** General\
**Created:** [25 July 2020 19:55 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696 "2020-07-25T19:55:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [25 July 2020 19:55 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696/1 "2020-07-25T19:55:26Z")

</div>

How would you do a default or else in a change node? I have a few values that if matched in the change node, get set to a text value. What I would like is for non-matching codes to default to "0".

Any ideas, or should I do this in a function?

---

<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:** [25 July 2020 20:04 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696/2 "2020-07-25T20:04:13Z")

</div>

why not use a `switch` node and have the last option an 'Otherwise"? Set your conditions 1 thru n-1 and have the outputs go to one `change` node and have condition 'n' be the 'otherwise' and have it go to another `change` node

![Screen Shot 2020-07-25 at 4.03.33 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a30a3b86bed4a97eb9d0402f4546405e76f504fd.png)

---

<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:** [25 July 2020 21:12 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696/3 "2020-07-25T21:12:30Z")

</div>

Can you show us an example of what you mean?

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [25 July 2020 21:48 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696/4 "2020-07-25T21:48:27Z")

</div>

Thanks, Zeno- that should work. That would mean entering the phone numbers twice, but there's only 9 of them that should translate to a code, everything else should be blank.

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [25 July 2020 21:51 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696/5 "2020-07-25T21:51:04Z")

</div>

Colin- I made a function to do what I need. In line 3 I set code to three dots, but when an incoming phone doesn't match anything, the msg.payload should be "...", but it isn't. Any idea why? (I am still learning how to write functions).

```auto
//Change phone numbers to the code
var phone=msg.payload;
var code="...";

if (phone=="8352281")
{
    code="803";
}

if (phone=="7425125")
{
    code="804";
}

if (phone=="725611")
{
    code="806";
}

if (phone=="8962788")
{
    code="807";
}

if (phone=="9821054")
{
    code="813";
}

if (phone=="9821045 ")
{
    code="813";
}

msg.payload=code;
return msg;

```

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [25 July 2020 22:06 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696/6 "2020-07-25T22:06:23Z")

</div>

Whoops. (Check my avatar).  
My problem was in an upstream node.

Zeno's switch worked as well as my function...

---

<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:** [8 August 2020 22:06 UTC](https://discourse.nodered.org/t/change-node-default-or-else/30696/7 "2020-08-08T22:06:23Z")

</div>

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