# Access to Scripts in Project Library from Session Events?

**URL:** <https://forum.inductiveautomation.com/t/access-to-scripts-in-project-library-from-session-events/76591>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 19, 2023, 3:21pm UTC](https://forum.inductiveautomation.com/t/access-to-scripts-in-project-library-from-session-events/76591 "2023-07-19T15:21:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Quinn](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@Colin\_Quinn](https://forum.inductiveautomation.com/u/Colin_Quinn)\
**Post date:** [July 19, 2023, 3:21pm UTC](https://forum.inductiveautomation.com/t/access-to-scripts-in-project-library-from-session-events/76591/1 "2023-07-19T15:21:40Z")

</div>

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

```auto
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.

```auto
	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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 19, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/access-to-scripts-in-project-library-from-session-events/76591/2 "2023-07-19T15:29:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin\_Quinn](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@Colin\_Quinn](https://forum.inductiveautomation.com/u/Colin_Quinn)\
**Post date:** [July 19, 2023, 3:41pm UTC](https://forum.inductiveautomation.com/t/access-to-scripts-in-project-library-from-session-events/76591/3 "2023-07-19T15:41:17Z")

</div>

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?
