vkuehn
2 February 2021 14:57
1
Accroding to the documentation it should work to set variables from a function node to the flow like that.
if (flow.get("bot_command")!==undefined){
flow.set("bot_command", "c0,0");
}
msg.payload = flow.get('bot_command');
return msg;
Also that didn't work
do I have to prepare something before using flow variables ?
gerry
2 February 2021 15:16
2
I think the expression should be
== 'undefined'
1 Like
vkuehn
2 February 2021 15:20
3
@gerry That did actually work, thanks.
Would you know how to do the same in a change node ?
You cannot do a 'set if not defined' type of rule in the Change node, but aside from that, you can set a flow context value. In the screenshot you've shared, I can see you were using msg.paylod
and not msg.payload
.
Colin
2 February 2021 15:31
5
That says that if it is not undefined then set it. Perhaps you meant if it is undefined then set it.
if (flow.get("bot_command")===undefined){
that syntax is frowned on, however, as the name undefined
can be set to a value. An alternative is
if (typeof(flow.get("bot_command")) === "undefined"){
or, if know that the variable should never be zero or false
or an empty string then you can use
msg.payload = flow.get("bot_command") || "c0,0"
flow.set("bot_command",msg.payload)
return msg
vkuehn
2 February 2021 15:36
6
@knolleary thanks changing it to payload did work....sorry posting a typo
it would be nice if that is possible
@Colin thanks for the hints
system
Closed
3 April 2021 15:37
7
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.