Change Node: Default or Else?

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?

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

1 Like

Can you show us an example of what you mean?

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.

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).

//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;

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

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

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