I need a simple switch with 2 outputs. One for "all conditions are true" (logically AND'ed) and one "otherwise".
For this to end, I create an empty dictionary on start (global scope):
let watchdog_status = global.get('watchdog_status') || {};
...the switch never fires on the expression, but always on "otherwise".
What am I doing wrong? (or is this an issue?)
My current workaround is to have a function node, that evaluates ALL conditions and stores the result in a single (global) value. That single boolean then can be checked in a switch (global.var "is true" -> output1; "otherwise" -> output2).
It's working but looks really dumb!
Try using the JSONata in the property. $count($globalContext("watchdog_status").*[$=true]) and == 2 in rule
Or false in $globalContext("watchdog_status").*
and is false in rule.
The JSONata test window is using the route msg scope, as is the JSONata in the rules.
Many thanks everybody for all your suggestions. @Buckskin, @smcgann99 : I tried that already (more like (cond1 and cond2) = true or even things like cond1 = true and cond2 = true. Nothing worked for me (again: it works in the test-section of the editor while the switch never fires).
It seems, the trick is to not use the dictionary as the property but an expression instead like @E1cid suggested!
For some reasons (idk), false in $globalContext("watchdog_status").* as property and is false in rule does not work.
But counting all booleans work! I now use this with a reverse logic so I don't have to care about the switch in case the number of booleans to check increase in the future - the switch failes as long as at least ONE (or more) of N booleans is false:
Property: $count($globalContext("watchdog_status").*[$=false]) and Rule: == 0 -> everything is fine! Otherwise: FAIL!
Btw: I use this for health checks in a multi flow (therefore the global context) container in kubernetes where the connected status to ttn is one condition beside others.