Message handler running but behind required timing

Hi all,

I'm currently working on a user management page and I'm working on a 'Remove User' button. In this button it calls an 'openPopup' function to ask the user to confirm that they want to remove the selected user. The problem I'm running into is the message handler will be ran with the last instance of the control variable not the one returned in the 'payload' object of the given call.

This is the script on the button:

def runAction(self, event):
	system.perspective.openPopup('myPopupId', 'areYouSureView', position = {'left':100,'top':100})
	if self.getSibling("Main_User_table").custom.didSelect == True:
		system.user.removeUser("workingAlone_DB", self.getSibling("Main_User_table").custom.user)

this is the message handler that is on a table component:

def onMessageReceived(self, payload):
	self.custom.didSelect = payload['didSelect']

and this is the scripting action on the button on the popup page:

def runAction(self, event):

I'm not sure how to either access the payload in the scripting of the button itself or how to force the script to wait until the message handler has received its new values (or some other way to make this function :sweat_smile:).

Thank you,


Your script doesn't stop when it opens the Popup, so all of the code after the openPopup call is still run in the background immediately after opening. In 99.99% of cases, the code you write in Perspective is going to be non-stopping code.

In your use-case, it make the most sense to disable the button until a user has made a selection. In the event the user has made a selection, enable the button, and when you open the Popup, pass along the selected user as a parameter of the View being displayed for confirmation.

I use a generic confirm popup that works like this:
The popup view takes 3 parameters: popup_id, message and handler.
The handler is the name of a message handler that will be called when the "confirm" button is called.
Now how you have to do is to put the confirmation handler somewhere on the page that opened the popup.

edit: Just to be clear, the message parameter has nothing to do with message handlers, it's just the message displayed in the popup, something like "Are you sure you want to do x ?"