How to deliver variable value to different flow when ui-button is pressed

Good day Guys. The first 3 image represents that I am trying to initialise a global variable "a" to be 1 whenever i press the button. And the value represented by variable "a" will be stored as "msg.test" and to be used in other FLOW.

The last 3 image shows the other flow that I am trying to obtain the variable "a" value into this flow.

But when i press the button on the dashboard, I want this flow to show its message on debug node right away WITHOUT clicking on the inject node.

P/S: The reason why im using global variable is because in my main flow, both the msg.topic and msg.payload is occupied with the constantly generated value from OPCUA client.

And i want it such that when i press the button, I want these data to be saved into MySQL database. Therefore, im doing some testing here to make sure that i can pass on the global variable instead of letting my msg.topic or msg.payload overwrite by the value sent from the "ui-button" when its pressed.




A flow will not run until something triggers it. Having a function node at the start of a flow will never run the flow, a msg has to be fed into the function node.

Why not also have a switch node connected to the button. Have it check the 'topic' ad iff it is a yes have the optput of the switch go to a link-out node. Have the link-out node connect to link-in nodes connected to the flows you need to run.

Sorry for the misunderstanding, As you can see from my overall flow here, the button node here is suppose to act like a gate which before it is pressed, no value will be able to pass through it to the function and save it to the MySQL data base.

please have a look at the code in this function node(after button node) , there is 1 line which consist both msg.topic and msg.payload.

Since button can only send msg.topic and msg.payload, lets say if i were to write the code like this:-

msg.topic = "INSERT INTO table1(value)VALUES(' " + msg.payload + " ');";


return msg;

i wont get the value that i desired if i do if(msg.topic=='pressed') condition, my value will become a random string number in mySQL database

or the value turns out to be just "pressed" if i use if(msg.payload=="pressed") condition.

However, if i were to remove this button node, everything works fine.

This is my concept,I am planning to implement a dashboard whereby, if the end-user wants to record this reading, they just have to press the button and the data will be saved in a MYSQL database.

Once again, so sorry for causing a confusion.

Please refer to the image shown in this link.

So just have the button attached to the nodes that builds the query and runs it. I don't see what is so hard about this.
Screen Shot 2022-07-14 at 8.55.13 AM

Or do you mean that you want to allow messages through or block them, by using a button? If so then have a look at node-red-contrib-simple-gate which can do that.

my primary concern is that , this button can only send msg.topic & msg.payload value right?

But both of these (msg.topic & msg.payload) exist in my function node(after the button node) as shown below:-

msg.topic = "INSERT INTO table1(value) VALUES( ' " + msg.payload + " ');";"

So lets say if i were to use "if" condition , i can only choose either to send Payload or Topic value when it is pressed. Which is what i dont want as this will overwrite the data in msg.payload and msg.topic that is to be stored into MySQL database.

I’m building an inventory system. On the input page in the dashboard I’ll enter data in some ui-text nodes. Each node sends its msg to a change node that stored it in a flow variable.

When the button is pressed a msg is passed to a change node. The change node will move all the flow variables to msg.payload as a object. That is passed to a template node that builds the query and puts it into msg.topic and then it is sent to the sql node.

Hi, thanks for your suggestion. I will give it a try when I get to my office tomorrow. Sorry I am running on on asia time zone here. I will update again tomorrow.