# Calling Project Library Script in a scheduled gateway event

**URL:** <https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 12, 2025, 11:03pm UTC](https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143 "2025-11-12T23:03:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsteele](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jsteele/32/40285_2.png) [@jsteele](https://forum.inductiveautomation.com/u/jsteele)\
**Post date:** [November 12, 2025, 11:03pm UTC](https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143/1 "2025-11-12T23:03:05Z")

</div>

I would like to use a gateway scheduled event to look for changes in a db. The scheduled event will run code every minute. When I see a change I would like to use scripts that I have in the Project Library scripts section. I would like to call those scripts from the gateway event script because I have already written all the scripts that work with the DB and the PLC. I cannot figure out how to call them or if it is even possible.

Also, is this the best way to look for a change in a DB?

I am using Ignition 8.3

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 12, 2025, 11:06pm UTC](https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143/2 "2025-11-12T23:06:03Z")

</div>

Not only is it possible, but putting your logic entirely in the project library is highly recommended. The event script becomes a one-liner:

```python
someLibraryPackage.someLibraryScript.someFunction()

```

(With argument passing for event types that have per-event metadata.)

When you get to the first dot, the editor's auto-complete should try to help you.

---

<div class="post-metadata">

**Author:** ![jsteele](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jsteele/32/40285_2.png) [@jsteele](https://forum.inductiveautomation.com/u/jsteele)\
**Post date:** [November 15, 2025, 7:10pm UTC](https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143/3 "2025-11-15T19:10:33Z")

</div>

I get the following errors when I try to run it. Any suggestions on what this error means?

If I run the Main.mainScripts() from a perspective button it works.

 ![Screenshot 2025-11-15 at 2.09.33 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/4/841621704cbcab5cf715ae9d69e9ad8ae589bd97.png) ![Screenshot 2025-11-15 at 2.08.49 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/d/3d774efd3d9e1e82072da2eff236f4382d198190.png)

 ![Screenshot 2025-11-15 at 2.09.05 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4d5b56dcdf98e721dda41e9e2b3ef229db6572c7.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 15, 2025, 7:45pm UTC](https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143/4 "2025-11-15T19:45:54Z")

</div>

Pictures are great for context but please also post copies of code as preformatted text. It helps to speed up the troubleshooting process by others, see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). You can edit your post to add it via the pencil icon in the bottom right.

Please also post the full error stack trace (if one exists) as preformatted text as well, the full trace will have important information to help troubleshoot.

Based on your existing logic and logging, I'd say the failure is somewhere in your `mainScript` function, likely in one of the other functions that you are calling. If you are touching a DB, you are likely getting a java db error which won't be caught as a python Exception.

Add

```python
except java.lang.Throwable as t:
    logger.warn("A java exception occured", t)

```

to your try block, this should catch any java errors.

Additionally, I would avoid having `import traceback` that late in the script (or in a function at all). Move the gateway script logic to a project library script and call it with a single line from the scheduled script. Import `traceback` at the top of the project library script outside of the function.

---

<div class="post-metadata">

**Author:** ![jsteele](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jsteele/32/40285_2.png) [@jsteele](https://forum.inductiveautomation.com/u/jsteele)\
**Post date:** [November 15, 2025, 8:11pm UTC](https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143/5 "2025-11-15T20:11:58Z")

</div>

Thanks for the information. And I will add the exception code.

I found the error to be cause by using system.perspective.print() statements in my other code, and maybe that is why it was fine when I called it in a perspective View but not a gateway script.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 15, 2025, 8:53pm UTC](https://forum.inductiveautomation.com/t/calling-project-library-script-in-a-scheduled-gateway-event/112143/6 "2025-11-15T20:53:32Z")

</div>

> [@ryan.white](#):
>
> I would avoid having `import traceback` that late in the script

imports should strictly only ever be used at the top of script libraries. Google jython import lock contention for context
