I have several old flows where I had to place along the flow a data that set the msg.variable to some sort of message and then pass along to Alexa announcements at that the end of the flow.
![image](https://community-assets.home-assistant.io/original/4X/7/0/7/707a4981d34c3fb0e558ffcb0e227180888d4a2b.png)
Catch 22
I am setting the msg.variable from another flow on another tab etc…
the issue now is that it says undefined… yadda yadda on echo when I pass the message: msg.variable…
so I then tried to set global.variable and attempted to have the message be message: global.variable but it still says undefined…
On the Person Object I set
![image](https://community-assets.home-assistant.io/original/4X/b/3/5/b35908e116303b816fcd1cbae1e42c7eefb6a795.png)
On the other flow I then have a data object that is taking in the global.alexaperson variable
msg.payload =
{
"data":
{
"message": global.alexaperson + " " + msg.alexaSpeak,
}
}
return msg;
what might I be missing?
I think you need to use global.get(“alexaperson”) to retrieve the value in the global variable.
Thank you @nickgeorge333 I would do this in a function somwhere before I call it and how do I capture it and write back to the variable global.alexaperson or another variable for use…
so I added at the top of the function the following…
const person = global.get('alexaperson')
msg.payload =
{
"data":
{
// "message": msg.alexaperson + " " + msg.alexaSpeak,
"message": person + " " + msg.alexaSpeak
and I get this in the debug now
SyntaxError: Invalid or unexpected token
You have a comma at the end of your commented line, but not at the new one. If you have more lines after that require the comma there, that could be your syntax error.
As far as writing to the global variable in the code. It is global.set(“alexaperson” , value)
So what do I use for value since I am setting that per person.name object…
example… person.frank object I added another parameter called global and alaexaperson and set it as frank. so when I const… do I do then…
const person = global.get(person,alexaperson)
hmmm
Ok Solved it…
Added a change node
and did the following
![image](https://community-assets.home-assistant.io/original/4X/8/1/c/81c021834d77122b6a4df6a0d921c4226c3b5d5e.png)
Then changed that function’s single line (didn’t need the declare)
"message": msg.person + " " + msg.alexaSpeak,
and it worked perfect!