Get all defined variables

Hopefully not too stupid of a question: Do we have the ability to retrieve all flow variables for a given flow, perhaps in the form of an array? If so, how would one go about this?

I assume you mean flow context?

flow.keys() returns a list of the names of the variables. You can then use flow.get() for each element in that array to get its value.

1 Like

That's exactly what I meant, thanks! Sometimes RTFM is tougher when you're bumbling about not knowing the right terms to search... once you replied, I was able to find this in the "writing functions" guide almost right away.

I also quickly threw together an example for anyone to play with if they run across this thread in their own searching. I have no doubt it could be done more elegantly; but what can't, really?

[{"id":"fe9afd72.aaacd","type":"inject","z":"6da4d638.9f76c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":1080,"wires":[["fe191abf.dd706"]]},{"id":"fe191abf.dd706","type":"function","z":"6da4d638.9f76c","name":"","func":"msg.payload = flow.keys();\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":1080,"wires":[["7d3aa3bd.491114"]]},{"id":"4615c07d.81d37","type":"debug","z":"6da4d638.9f76c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":1080,"wires":[]},{"id":"7d3aa3bd.491114","type":"split","z":"6da4d638.9f76c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":470,"y":1080,"wires":[["d9b8dd89.1c1fa8"]]},{"id":"d9b8dd89.1c1fa8","type":"function","z":"6da4d638.9f76c","name":"","func":"var key = msg.payload;\nvar val = flow.get(key);\nmsg.payload = {\"variable name\":key, \"value\":val};\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":1080,"wires":[["4615c07d.81d37"]]}]

1 Like