Zenofmud
unread,Jul 26, 2017, 6:35:36 AM7/26/17Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to node...@googlegroups.com
npm: v3.10.10
node: v6.11.0
node-red: v0.17.4
OS: OSX 10.11.6
While trying to help on another thread, I tried an experiment to use the change node to increment a global (and a flow) variable using JSONata but it doesn’t work. Attached is a flow and image of the flow.
Tests
--------
Step 1 initializes global.counter
Step 2 moves global.counter to msg.payload and dumps it (via debug)
Step 3 attempts a JSONata on the global.counter and moves it to msg.payload and dumps it
Step 4 moves global.counter to msg.payload and does the JSONata to msg.payload
Step 5 just puts a different value in the global to make sure things change.
Conclusion: you can (currently) use JSONata on flow or global variables.
Question: Does JSONata only work with msg.xxxx or this bug?
[{"id":"df8bd2ff.2d4ea8","type":"inject","z":"e3e564e7.9d276","name":"Step (1) initilize Global.counter","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":200,"y":1460,"wires":[["49a6c154.d49498"]]},{"id":"49a6c154.d49498","type":"change","z":"e3e564e7.9d276","name":"set global.counter","rules":[{"t":"set","p":"counter","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1460,"wires":[[]]},{"id":"834d644a.b5125","type":"inject","z":"e3e564e7.9d276","name":"Step (2) dump global.counter","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":200,"y":1500,"wires":[["7a4cd2f4.51a42c"]]},{"id":"ca4b684e.2d62a","type":"debug","z":"e3e564e7.9d276","name":"Display msg.payload","active":true,"console":"false","complete":"payload","x":800,"y":1500,"wires":[]},{"id":"7a4cd2f4.51a42c","type":"change","z":"e3e564e7.9d276","name":"Set msg.payload = global.counter","rules":[{"t":"set","p":"payload","pt":"msg","to":"counter","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1500,"wires":[["ca4b684e.2d62a"]]},{"id":"db1f26ec.743d3","type":"change","z":"e3e564e7.9d276","name":"","rules":[{"t":"set","p":"counter","pt":"global","to":"(global.counter +1)","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"counter","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":1540,"wires":[["d28da755.c7f88"]]},{"id":"9a9ce4b9.6a984","type":"inject","z":"e3e564e7.9d276","name":"Step (3) attempt jsonata on global","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":220,"y":1540,"wires":[["db1f26ec.743d3"]]},{"id":"d28da755.c7f88","type":"debug","z":"e3e564e7.9d276","name":"Display msg.payload","active":true,"console":"false","complete":"true","x":800,"y":1540,"wires":[]},{"id":"c26ab0ed.b7444","type":"change","z":"e3e564e7.9d276","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"counter","tot":"global"},{"t":"set","p":"payload","pt":"msg","to":"(msg.payload + 1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":1580,"wires":[["71c0e205.6ee3d4"]]},{"id":"bea39865.1152a","type":"inject","z":"e3e564e7.9d276","name":"Step (4) jsonata on msg.payload","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":210,"y":1580,"wires":[["c26ab0ed.b7444"]]},{"id":"71c0e205.6ee3d4","type":"debug","z":"e3e564e7.9d276","name":"Display msg.payload","active":true,"console":"false","complete":"true","x":800,"y":1580,"wires":[]},{"id":"e3bd860c.3beab","type":"inject","z":"e3e564e7.9d276","name":"Step (5) set Global.counter to 20","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"x":210,"y":1640,"wires":[["bc8a824e.5aa498"]]},{"id":"bc8a824e.5aa498","type":"change","z":"e3e564e7.9d276","name":"set global.counter","rules":[{"t":"set","p":"counter","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1640,"wires":[[]]}]