Open popup from session event

New to Ignition here,

I’m trying to open a popup inside the Barcode Scan session event. The popup is not visible.


When I execute the exact same line of code as a script inside a button click event, it works with no issues. What am I missing?



Hello, Carlos! Welcome!

Are you testing this on a mobile device using the Perspective App? The Barcode Scan session event is designed specifically to interface with a mobile device and it’s camera app/hardware. The 8.1 documentation says this event will be ignored in a browser session.

Native App Functions

Yes, mobile device. The event executes properly, as I am setting some custom session properties inside it that are updating properly.

1 Like

Session Events have no context of “page”.

Consider the following code:

def runAction(self, event):
	This event is fired when the 'action' of the component occurs.

		self: A reference to the component that is invoking this function.
		event: An empty event object.

Note that you are NOT supplying a pageId. This sort of usage allows the thread in use to fallback to the page which is in use, because this is from a Button, which must belong to a View, which must belong to a Page in some capacity.

Now consider the following code:

def onBarcodeDataReceived(session, data, context):
	Called when a session is running in a native application and it has received
	barcode scan data

		session: The perspective project session.
		data: The data returned from the barcode scan.
		context: The user-defined context object associated with the barcode
		         scan event.

Note that you are still not supplying a pageId arg (or kwarg), but this script is NOT part of any component/View/Page. It does have information about the session it received the invocation from, but it has no context as to what page of that session to open the Popup on.

So, given that, there are two ways to do what you want:

  1. (Recommended) in the Barcode Scanned event, use system.perspective.sendMessage("BARCODESCANNED", payload={"data": data}, scope="session"), and then configure a Message Handler listener (named “BARCODESCANNED”) which then invokes your openPopup code.
  2. Loop through the available page Ids of the session object in the Barcode Scanned Event and invoke your code for each page of the session. This is not a good solution because it would open the Popup on EVERY page, instead of the page which originally scanned the barcode. I’ll include the code for this in case you want to try it.
for user_session in system.perspective.getSessionInfo():
    if =  # if potential user session is this session
        for pageId in user_session.pageIds:  # for every page of this session
            system.perspective.openPopup(“0”,‘Popups/PopupLoginAck’, pageId=pageId)
1 Like

I implemented the Message Handler and it worked like a charm. Thanks,


Hello @cmallonee where has to be implemented the message handler listerner? In the session events? I tried but doesn't work

No, placing the handler at the Session Event level will not work unless you specify pageId values because the Session doesn't know which page to open the Popup on. The most sense in this scenario is to place the Message Handler on the component scanning the barcode which triggered the event, but really it could be any component you expect to be visible to the user when the sendMessage call is invoked. Just remember that the Message Handler must be scoped to listen at the session level.

Thanks a lot, it worked.
Is better to use a messageHandler on a component or pass pageId in a session message handler in this case? If the second, how can you pass pageId?

It's better to place the handler on the component, precisely because you have no knowledge about which page to act upon. In theory, the pageId could be sent along as part of the Barcode Scanned Event as part of the context, but that's a lot of unnecessary overhead when you can just let a component known to be present on the page do what you need without all of the unnecessary passing of arguments.

1 Like