Switch a message depending on another variable

I am wanting to switch a message depending on another variable.

Looking at the switch node, that seems beyond the scope of that node.

Anyone got any ideas how to do that?

Example:
set flow.variable in another part of the flow.
New message comes in.
Depending on what flow.variable is, depends on where the message is sent.

I'm guessing that is getting into the function node's territory.

image

1 Like

(Know where I can get a new brain?)

HOW did I miss that?

Thanks.

I just have to check that is actually going to do what I want.
(That's the next problem)

1 Like

Ok, I have moved a few squares forward.

I have the flow.variable set.

A new message arrives. Initial thoughts were that what I said first off is/was good enough.
Alas I didn't think it though all the way - typical. I know.

Now I am wanting to know if I can multiple switch messages in the one node.

So:
If flow.variable is condition and if msg.payload != this or that.

I'm guessing it will have to be two (or more) nodes cascaded after each other to get that done.

You possibly "could" use a JSONAta expression but I'd stick with much clearer and easier solution of sequential switch nodes.

Then later on, convert them to a custom function node if you want to save some editor real estate space :slight_smile:

(Since we are still talking here....)

This is the next stage of the problem with the switch node:

I have flow.context data set.
I build a message with a section set. (Shown)
Injecting the switch seems to send it the wrong way.

It should go to output #1. (not 2)

Screenshot%20from%202019-08-20%2023-34-38

Is that clear with the piccies?

It shouldn't be going where it is - thus the node is called "NOT WANTED JUST NOW". (last picture)
The switch says if (flow.get) == msg.who
And as far as I can see it does.

(Weird happening)

Trying something this is now working.
But look at the red lines showing the names.

I did this (I was trying to reverse the comparison names and forgot to take the _1 suffix from one of the nodes.

IT WORKS!

Why?

Not for me.
It would be better to create a separate tab, where you recreate the problem in a simple flow.

Picture 1
The flow context is set to D1 called who_1
Picture 2
You can see the comparison done in the node to determine message switching.
It looks at msg.who and compares it to flow.who_1
Picture 3
You can see the change node setting msg.who to D1
Picture 4
You see the message with msg.who set to D1 going through the switch node (double red circles) and coming out on output #2.
This goes against what was shown if msg.who == flow.who_1

Now with the latest post that if I make them both who_1 it works.

To me that is weird.

Incidentally, I think that you could also use a finite state machine for this kind of routing? Probably only worth it for more complex examples though.

Thanks, but that is really REALLY beyond my skill.

(And there is another gremlin I realise too)

If the flow.who is empty, it has to go to output #1. Although it doesn't match.
I think I will have to put a function node here rather than a switch.

Bed calling.
Night!
Thanks for the replies.

And before you know it, your flow is more complex and difficult than using a FSM :wink:

Yup. I seem to be destined to be . . . . haunted (?) by things I don't understand.

Well you can be haunted by it or you can embrace it! Keeps you young!!

True.

I have downloaded the "FSM" node, but it just seems too vague for me at this time.

Oh, there are two.
FSM and finite-state-machine.

Any preferences?

DSM is actually the better and more maintained one - the author is often on the forum also

Craig