I'm taking the wonderful course: A Developer's guide to Node-RED. And I've just learned about JSONata (very cool). I'm done with the homework assignment and this is not my homework. But I do have a question on using JSONata expressions in a switch node and using $globalContext('varNom').
I've found that if I set varNom to a value (let's say true) inside a node-red flow with global.set('varNom', true) that I can't use it in a JSONata expression
( Ex: $globalContext('varNom') = false).
Here's my example code
[{"id":"b4440ae7.c76a88","type":"change","z":"d275358f.727568","name":"(($globalContext('varNom')) = false)","rules":[{"t":"set","p":"payload","pt":"msg","to":"(($globalContext('varNom')) = false) ? \"An: 1\" : \"AN: 0\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":503.01422119140625,"y":405.00567626953125,"wires":[["56cf54ae.8737cc"]]}]
The flow is broken into 3 parts,
- the first part is to set the varNom to true or false
- the second is the test switch with
- JE: (($.payload.nom = "string") and ($globalContext('varNom')) = false)
- JE: ($.payload.nom = "string") and $globalContext('varNom')
- JE: ($.payload.nom = "string")
- Otherwise
- I've selected Stop after first match .
- in the third section you can see the equivalent result of the output using the change node
When I set varNom to false, the debug shows that the result is on output 2 (???). I'm expecting it to be on output 1.
When I set varNom to true, same output. I also tried setting the 2nd expression to $globalContext('varNom') = true but that returns false and output on 3. In my last section you can see the equivalent result of the output using the change node. I'm finding JSONata expressions to be very confusing.
So my question is, how do you use the JSONata expressions with $globalContext('varNom')?