Using flow variable in if statement

I want to save a value in a flow variable once and then compare it to incoming a msg.payload field in an if statement (using a function block)

I have saved the value I want to compare
then I load it into the colora variable

colora = flow.get(“color”)

now I want to compare that value in color it to a field in an if statement

if (msg.payload.id === colora)
{msg.payload.new= “blue”}
else {msg.payload.new=“white”}

my problem is that it never detects when msg.payload.id actually matches the value in the flow.color field so everthing is “white”.....but I can't figure out the syntax to have msg.payload.id compare to the value in colora. (neophyte to node-read)

what's the syntax for this....or should I forget about using calora and just insert the flow.get into the if statement (and again, what's the syntax)?

Any help appreciated...

I'm not at a computer to test it, but have you tried...
if (msg.payload.id == colora) <<< i.e. with two equal signs.

It would be helpful if you published your flow.

I would put in some debug nodes to check for the values of your msg and if you have used the right variable.

solved....forgive a newby :slight_smile: I changed flow to global and now it works. I guess I don't understand when to use flow and when to use global.

That doesn't make sense to what you said.

Yes, if you put flow.get( instead of global.get( but as @dynamicdave said you need to use two = signs, not three.

Yes, it is ok to make mistakes when you are new to using Node-red - I've made my fair share.

Did you read the documentation? https://nodered.org/docs/user-guide/context
If that confuses you, what confuses you and I'll try to explain.

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