I've got several flows and I've just started cobbling together a dashboard.
On my dashboard flow that I use to populate the dashboard, I have a stand alone function that I use to call a global context GasTankStatus, so that I can put the status of the tank (empty or not empty) on my dashboard. I know the Global Context is there and I have the right path.
But when I use the function to try to get it and then send it along to a Dashboard Text module, I'm being told msg is undefined.
Since nothing is calling this function with a message, I figure I should just declare a msg in the ON START tab and send it that way. But when I try, it tells me MSG is already defined. But if I don't declare it there and have it send, the debug tells me it's undefined.
I imagine this function might only fire once since it's not receiving a message (and I don't know if it fires every 5 seconds or not, so it may not achieve what I am trying to do) but I'd like to know why I can't get it to send anything to the text module.
Your code var msg = ""
is attempting to declare msg as a new variable, but msg already exists, hence the error.
Something like var newmsg = "" would be allowed.
But note that if you did that, the next line "newmsg.payload = "EMPTY" would give an error because you just declared newmsg as a string and now you are trying to use it like an object.
I don't know exactly what your function is intended to do, but it is in the nature of nodes that they make changes to the msg object, so you may be able to get away with not declaring a variable but just setting msg.payload = "EMPTY"
That's what I would have thought as well. But when I just tried msg.payload = "EMPTY" it would then result in that debug error of msg not defined. But if I tried to define it in there as a var then it said it was already there. So it was a Catch 22.
Instead of having the function floating by itself (nothing feeding into it), I just tied it into an existing node and did it that way. Now it works.