How can i mention my "ui-button" code in the function node when it is pressed?

Hello guys, i wanted to implement an "if "statement to execute the action once the button is pressed. By referring to my simple code below, other than using msg.payload or msg.topic , is there any other statement i can use to tell the program that the button has been pressed? I tried using " Button.isPressed()" , but it wouldnt work.. any suggestion?


msg.topic ="Yay"


msg.topic = " Not working"

return msg;

Pressing the button will start the flow, so setting the msg.topic to (for example) "buttonpressed" in the button node, and feeding that into a function node, you can then use;

if (msg.topic == "buttonpressed") {
do something

If you are then using an if/else statement, you will probably need to get those states from saved context first, to ensure that their values are available when the button is pressed.

Hi. Thanks for the heads up. The thing is i am using OPC UA to obtain the data and thus my "msg.payload" & "msg.topic" are both occupied with existing data value. And that is why im seeking for other alternative term as to not overwrite the data in the msg.payload and topic.

if (msg.topic == "existingdata") {
do something
} else if (msg.topic == "buttonpressed") {
do something different 

I thought the message was coming from a ui-button.

Hi, sorry for the misunderstanding. The msg.topic contains "variable" values that is generated through the OPC-UA client node. And i would like it to display the data on the MySQL database only when i press the button on the dashboard.

The second image shows the code im trying to implement in the function node after the button node. This is what i meant by both the "msg.topic" and "msg.payload" are pre-occupied with values.

The third image is part of the configuration page of the ui-button node. there is only 2 term here that can be delivered upon button pressed. is there any other term that i can use other than these two?


msg.topic happens to be a variable generated via the OPC UA-client node.

I would remove the button node from your flow, and use it to start a new 'stand alone' flow instead.
The new flow would run when you press the button and retrieve the latest data from your database.

So the new flow would comprise;
Button node - to run the flow
Function node - to format the query
Mariadb node - to retrieve the latest data

I don't use mariadb, so you'll have to do some searching to format the query.

hi Paul. Ive tried to create another flow(with button,function and debug node) mainly just to trigger the process in another flow. for button,Ive set the payload to be delivered to be a string('yes') when button is pressed.

Image 1 & 2 is the flow and the code respectively. this button on the dashboard, when pressed, it should trigger the process in other flow(shown in image 3 & 4).

The issue here is, i couldnt get the variable reading(image 3) that i have initialised in my other flow(image 1).

Im guessing there is some issue with my code.




Is this a different question to what you initially asked?
I thought that you wanted to push a button, which would retrieve the last value saved to Maria.db?

I'm now confused what exactly that you are trying to achieve.

Looks like Jack has opened a second thread with the same question

@JackJackTan414 Please done post the same question more than once, it wastes people's time.

A post was merged into an existing topic: How to deliver variable value to different flow when ui-button is pressed

Topic closed because OP has duplicate post...