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)

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