How to compare and evaluate values in the function node

Hello Guys
I'm stuck probably with a beginner problem.
I want, if the Input "ns=4;s=Arp.Plc.Eclr/M_HS_Node_Red_1" is not equal "1" and the input "ns=4;s=Arp.Plc.Eclr/M_HS_Node_Red_Anf" is "true" then send out "true" else send out "false".

Here is my code:

if ( (msg.topic == "ns=4;s=Arp.Plc.Eclr/M_HS_Node_Red_1", msg.payload !=1) && (msg.topic == "ns=4;s=Arp.Plc.Eclr/M_HS_Node_Red_Anf", msg.payload = true))
        msg.payload = true;
        msg.payload = (msg.payload === "true") ? true : false;
        return (msg.topic = "ns=4;s=Arp.Plc.Eclr/M_HS_Node_Red_Anf1",  msg.payload);
        msg.payload = false;
        msg.payload = (msg.payload === "false") ? true : false;
        return (msg.topic = "ns=4;s=Arp.Plc.Eclr/M_HS_Node_Red_Anf1",  msg.payload);

But it doesnt work.
I hope, anybody can help me.
Thanks Dominic

Hmm, where to start...

  • logical AND is &&
  • logical OR is ||

Setting msg.payload = true then checking to see if it EXACTLY matches "true" will always be false.

You cannot tests different variables if they are not inside the same message.

Lastly, as this is a low-code environment & what you are asking is pretty simple, there is no need to use a function node. Especially true since you do not understand the JavaScript syntax. In low code a set of "switch" and "change" nodes should be all you need.

If you want further help, you are going to have to show us what values to get (aka use debug nodes) and share your flow.

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