Access to Scripts in Project Library from Session Events?

Hi all,

I have a perspective application that currently handles barcode scanning through session events. There is also a script in the Project Library that I use to output any error messages with a popup. This script sits in the functions file within the project library, so I use that to access the function itself, shown below

def show_error_popup(header, message):
    system.perspective.openPopup('error-popup', 'error-popup', params = {'header': header, 'message': message}, modal=True, draggable=True, resizable=False, closable=True )

Then the session event for onBarcodeDataReceived has the following setup, where I check which type of barcode is expected, and query the database to see if it exists.

	valueNotFound = 'Scanned item was not found, please verify that it is a valid warehouse barcode'
	
	if context['event'] == 'scan':
		# clicked to scan container
		if context['barcode_type'] == 'container':
			params = { 'container_uuid': data['text'] }
			try: 
				res = system.db.runNamedQuery('check-container-type', params)
				functions.show_error_popup('debug', res)
				session.custom.scannedData.container = { 'data': data['text'] }
			except:
				functions.show_error_popup('WARNING', valueNotFound)

I believe it is failing when I call functions.show_error_popup(). Is there any way to get access to those project library scripts within the session events?

You can, just as you have there. The complication is probably that barcode scan events don't run with full access to the Perspective page, so openPopup is likely failing; I'd check your gateway logs to confirm.

From the barcode scan event hook, you could broadcast a message (system.perspective.sendMessage) and have a message handler for it on a docked view or somewhere else that itself calls the error popup function? Annoyingly indirect, I know.

I am thinking I may just return the value back out to the button that triggered the scan event and let the "view" handle any potential errors from the query. I think that should work but there might be race conditions between the button's script running and the actual return of scan data?