Linking two or more conditions in a function node - syntax?


I need the syntax for a function node to compare at least 2 conditions at the input and then generate a result accordingly.
e.g. At the input the values 20 and 40 come from 2 nodes.
Now the connection: If payload 1 = 20 and payload 2 < 40 then
output "Error".
If payload 1 >20 and payload 2 <40 then
output "Correct", etc.

Since I don't have any knowledge, I can't understand the required syntax in a function node.

Can anyone help?

Hi @pinie_pinie

There are a few ways to accomplish this.

One that springs to my mind is using the join node.
you can set it to output a key:value pair after n payloads have been received.

The key will be the topic of each incoming payload.

[{"id":"d18ef770d90dd6f9","type":"inject","z":"5f4f6ef5a6e88063","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"M1","payload":"","payloadType":"date","x":2110,"y":215,"wires":[["11566532fd5b14da"]]},{"id":"fc46771fd736960d","type":"inject","z":"5f4f6ef5a6e88063","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"M2","payload":"","payloadType":"date","x":2115,"y":255,"wires":[["11566532fd5b14da"]]},{"id":"11566532fd5b14da","type":"join","z":"5f4f6ef5a6e88063","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":2325,"y":240,"wires":[["56aecb562d938a0e"]]},{"id":"56aecb562d938a0e","type":"debug","z":"5f4f6ef5a6e88063","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2535,"y":240,"wires":[]}]

In a function node after the join you can then do.

if(payload.M1 === 20 && payload.M2 < 40){
  // do stuff


Thanks, I understood the first steps but how do you get the desired result?
flows(1).json (1.4 KB)

Hi @pinie_pinie

Sorry - I missed msg in my example.

if(msg.payload.M1 === 20 && msg.payload.M2 < 40){
   msg.payload = "Error"
} else {
   msg.payload = "OK"
return msg;

msg is the entry point into the message flowing through everything


that's exactly how I wanted it. I tested it with three conditions and it worked. The “Join” node is the crucial point.
Many thanks for the quick response.

1 Like