# Access project script from a Gateway Timer Script?

**URL:** <https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [May 23, 2022, 8:12pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926 "2022-05-23T20:12:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [May 23, 2022, 8:12pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/1 "2022-05-23T20:12:57Z")

</div>

Following the suggestion here [Can I call a Project Script from a Gateway Timer Script?](https://forum.inductiveautomation.com/t/can-i-call-a-project-script-from-a-gateway-timer-script/18693)

I’m trying to read a project script variable from a Gateway Timer Script. The Gateway timer script errors with (`name 'Gages' is not defined`) where `'Gages'` is the name of the project.

The line of code in the Gateway Script is `Gages.Globals.printCount`

```
params = {'msgID':'timer test',
		  'message':Gages.Globals.printCount,
		  'msgSource':'msgSource'}

```

Can anyone help?

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [May 23, 2022, 8:16pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/2 "2022-05-23T20:16:35Z")

</div>

> [@rvaught](#):
>
> Gages.Globals.printCount

This should be Gages.Globals.printCount() you are missing the () .

---

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [May 23, 2022, 8:19pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/3 "2022-05-23T20:19:19Z")

</div>

I get the same result with and without the ()s

`Gages.Globals.printCount` is an integer type variable if that helps?

![gtwy](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/2/428b1fb0929c154abbfecd9f4904e0076853a997.png)

The Gateway script (below) line with arrow is erroring

 ![gtwysc](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/3157e76c6bfa47fd9de303f4bb4a2f7051a04024.png)

---

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [May 23, 2022, 8:46pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/4 "2022-05-23T20:46:28Z")

</div>

Possibly the project must be flagged as Inheritable?

---

<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:** [May 23, 2022, 8:48pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/5 "2022-05-23T20:48:50Z")

</div>

Inheritable (and the ‘Gateway Scripting Project’ setting) are irrelevant here (making the project inheritable would guarantee this wouldn’t work, actually). You’re not leaving the project scope, even though you are _executing_ on the gateway.

What happens if you move the try/except block you have in the timer script into a(nother) project library script? So the gateway timer script becomes _only_ `callMyProjectScript()`?

---

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [May 23, 2022, 8:54pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/6 "2022-05-23T20:54:14Z")

</div>

If I’m understanding correctly. . . When I remove the try-catch error handling nothing happens at all. Nothing is logged via `system.db.runNamedQuery`. The only way to see the `name 'Gages' is not defined` error is by looking at the gateway logs

---

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [May 23, 2022, 9:00pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/7 "2022-05-23T21:00:29Z")

</div>

I removed the project name ‘Gages’ from the problem line and it works now. (see pic)

 ![gtwyscY](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bb058d40e9a0498ba3da060456dc520a63041780.png)

It’s confusing though I thought this would be out of the scope of the individual projects because it is (on the Gateway)?

Edit: If this matters, I am accessing the menus (Project)(Gateway Events)(Timer) from within the (Gages) project. But still, my understanding was that these scripts (Gateway Scripts) ran on the Gateway with a different scope. Regardless I seem to have gotten around my issue and appreciate you going over it with me. Thank you!

---

<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:** [May 23, 2022, 9:23pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/8 "2022-05-23T21:23:11Z")

</div>

Oh. Right.

Okay, this takes some setup.

There’s two orthogonal concepts here:

1. Where the script is _actually being executed_. This is the client/designer vs gateway scope.
2. Where the script is defined. _Basically_, everything you configure in the designer (with the exception of event scripts _actually on tags_) is scoped within a particular project (even if it’s being run on the gateway!) - thus, even though gateway timer scripts, as the name implies, are _executing_ on the gateway, they are still within the _context_ of a particular project, and thus _implicitly_ have access to that project’s script library.

As a related point - there is _no way_ to conditionally reference or otherwise ‘qualify’ a reference to _another_ project’s script library. You are either using your own script library (which could have inherited resources in it), _or_ in the case of e.g. scripts _on tags_, since there is no associated project, you’re using the ‘Gateway Scripting Project’.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [May 23, 2022, 9:44pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/9 "2022-05-23T21:44:50Z")

</div>

> [@paul-griffith](#):
>
> As a related point - there is _no way_ to conditionally reference or otherwise ‘qualify’ a reference to _another_ project’s script library. You are either using your own script library (which could have inherited resources in it), _or_ in the case of e.g. scripts _on tags_ , since there is no associated project, you’re using the ‘Gateway Scripting Project’.

Out of curiosity, is there a defined reason as to why this shouldn't be allowed? Lets say we have a gateway with several different projects that essentially act as script libraries, that can all be individually managed and updated through git. As well as a project that implements some but not all of those scripts, since you can only have one inherited project than you must put this all in one project, making it harder to version control the separate individual sup-libraries inside of it.

Being able to fully qualify a script in another project would allow you to have multiple independantly controlled llibraries all in different repositories, but accessible to one or many projects?

---

<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:** [May 23, 2022, 9:50pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/10 "2022-05-23T21:50:54Z")

</div>

My immediate thought would be that, effectively, we would have to always reload all scripts anytime _any_ project updates its project library. That would be a _big_ penalty for a _very_ marginal use case.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [May 23, 2022, 9:52pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/11 "2022-05-23T21:52:16Z")

</div>

Does that already happen for an inherited project? And furthering the question, is there a reason not to allow multiple inheritance for this same case?

---

<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:** [May 23, 2022, 10:00pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/12 "2022-05-23T22:00:24Z")

</div>

> [@kgamble](#):
>
> defined reason as to why this shouldn’t be allowed?

What you are asking for is effectively multiple inheritance. Sorry, that's like, a _ **big** _ deal. Don't hold your breath.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [May 23, 2022, 10:13pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/13 "2022-05-23T22:13:46Z")

</div>

> [@pturmel](#):
>
> What you are asking for is effectively multiple inheritance. Sorry, that’s like, a _ **big** _ deal. Don’t hold your breath.

Yeah I agree that's exactly what I am asking for, I guess my question is, is there a reason it shouldn't happen, more than "its a lot of work and likely wouldn't happen any time soon"

---

<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:** [May 23, 2022, 10:18pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/14 "2022-05-23T22:18:34Z")

</div>

The best opportunity for multiple inheritance has passed. IMNSHO, it should have been implemented instead of hierarchical single-inheritance for v8.0. But nobody asked **me**. Huh.

Mixing hierarchical and multiple inheritance is horrifically complicated and likely bug-prone. So, not just a lot of work and not any time soon, but _ **risky** _ to deploy. /:

---

<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:** [May 23, 2022, 10:19pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/15 "2022-05-23T22:19:32Z")

</div>

It's an explosion of resolution complexity, with associated maintenance and quality assurance burden.  
It's [hard](https://en.wikipedia.org/wiki/Multiple_inheritance#The_diamond_problem), just on its own merits.  
You're only asking for it in the context of scripting resources, but the obvious followup would be "why can't I do it for X resource type"? Also, inserting "special" behavior for special resource types is a large part of why 7.9's resource system was so fraught with weird edge case behaviors - right now, we're consistent throughout, which is a huge boon overall.

Last, as I alluded to - while it definitely would be useful to folks like you and Phil...it probably wouldn't be useful to a lot of our customers. The business case to justify a shakeup that fundamental _probably_ just isn't there. I've learned to never say never, but right now the calculus just doesn't make sense.

> [@kgamble](#):
>
> Does that already happen for an inherited project?

Yes, 'upstream' changes to a project library will kick down to inheritors.

---

<div class="post-metadata">

**Author:** ![rbachman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbachman/32/43718_2.png) [@rbachman](https://forum.inductiveautomation.com/u/rbachman)\
**Post date:** [March 14, 2023, 7:11pm UTC](https://forum.inductiveautomation.com/t/access-project-script-from-a-gateway-timer-script/59926/16 "2023-03-14T19:11:20Z")

</div>

We are having an issue that might be tangentially related. _Occassionally_ when we open a specific project (called the Gantry project) in the Designer, the timer scripts will suddenly stop executing. To fix this, all we have to do is **Save** or **Update** the project from the designer.

The issue happened again today, and I discovered errors in the logs that corresponded to the Gateway Timer Events:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/4/34f8e9079c6bb65ef2b34f948f2642a829d48432.png)

The odd thing is that the package the error is referencing (called "project") is _in_ the project that is executing the gateway event.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/7/475e2227f78447291202f4261b26b8d6a7d71ff6.png)

My working theory at the moment is that the Designer must be somehow "checking out" the script when it first opens, and if the timing is _just perfect_, it might somehow cause the Gateway to not see the scripts or packages until the Designer has merged its changes with the Gateway.

We have other projects which also have Timer events, and we have only seen this issue 1 time with any of the other projects, but the Gantry project is executing the Timer script every 1 second, which is why I think we see it more often with this project.

Any idea what might be happening?
