# How to get "GatewayContext" in Gateway Event (timer) script

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [May 5, 2019, 8:51pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668 "2019-05-05T20:51:05Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul.bouillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.bouillon/32/7980_2.png) [@paul.bouillon](https://forum.inductiveautomation.com/u/paul.bouillon)\
**Post date:** [May 5, 2019, 8:51pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/1 "2019-05-05T20:51:05Z")

</div>

Hello,

Wondering if anyone knows how to gain access to the “[gateway context](http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.0-beta/com/inductiveautomation/ignition/gateway/model/GatewayContext.html)” from within a gateway event script in v8?

in v7 I think it would have been something like:

```auto
from com.inductiveautomation.ignition.gateway import SRContext
context = SRContext.get()

```

but haven’t been able to find anything similar in the v8 SDK

Thanks in advance!

-Paul

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 5, 2019, 9:24pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/2 "2019-05-05T21:24:37Z")

</div>

`SRContext` was renamed `IgnitionGateway`. Everything else should be the same.

---

<div class="post-metadata">

**Author:** ![paul.bouillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.bouillon/32/7980_2.png) [@paul.bouillon](https://forum.inductiveautomation.com/u/paul.bouillon)\
**Post date:** [May 6, 2019, 1:59pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/3 "2019-05-06T13:59:14Z")

</div>

awesome – thanks Kevin!

---

<div class="post-metadata">

**Author:** ![rttwge](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rttwge](https://forum.inductiveautomation.com/u/rttwge)\
**Post date:** [May 16, 2019, 1:12pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/4 "2019-05-16T13:12:19Z")

</div>

Hello,

Wondering if using IgnitionGateway in place of SRContext worked for you? Using the same class path but switching to IgnitionGateway, I’m getting cannot import IgnitionGateway or other flavor of error.

Thanks,

Rick

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2019, 1:19pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/5 "2019-05-16T13:19:17Z")

</div>

Are you using Ignition 8? Where / what kind of script are you trying to use this in?

---

<div class="post-metadata">

**Author:** ![rttwge](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rttwge](https://forum.inductiveautomation.com/u/rttwge)\
**Post date:** [May 16, 2019, 1:26pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/6 "2019-05-16T13:26:00Z")

</div>

Hi Kevin,

Using 8.01. I originally had the script in a package under user-lib … pkg.(a number of script files)

I’ve since moved the package to the global gateway scripts. All was working well (either place) except for the call to SRContext.

Finding this thread I gave IgnitionGateway a try but it isn’t being found. I’ve NOT tried putting this back under user-lib.

Thanks,

Rick

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2019, 1:29pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/7 "2019-05-16T13:29:00Z")

</div>

Sure, but where is this script being called from? What scope?

---

<div class="post-metadata">

**Author:** ![rttwge](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rttwge](https://forum.inductiveautomation.com/u/rttwge)\
**Post date:** [May 16, 2019, 1:33pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/8 "2019-05-16T13:33:55Z")

</div>

Ah, sorry … long running SFC also in the global project.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2019, 1:41pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/9 "2019-05-16T13:41:09Z")

</div>

Hmm. Well I think that should work… not sure what’s going on. Can you post the full error message when you get a chance?

---

<div class="post-metadata">

**Author:** ![rttwge](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rttwge](https://forum.inductiveautomation.com/u/rttwge)\
**Post date:** [May 16, 2019, 1:56pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/10 "2019-05-16T13:56:09Z")

</div>

Hey Kevin,

Well, what I said wasn’t the error, got past that a few days ago, that’s what I get for putting this down a few days ☹

Anyway, the error is this:

```auto
> Error in Step 'Action' in chart 'a6bea3af-834b-43ba-942e-ff3b9b406a20' for station 'Test-OP005 Traceback (most recent call last):
> File "<Script name="">", line 16, in onStart
> File "<module:sit.telegrams.actions>", line 180, in run
> File "<module:sit.telegrams.util>", line 38, in tag_subscribe
> AttributeError: 'com.inductiveautomation.ignition.gateway.tags.mode' object has no attribute 'subscribe'

```

So, IgnitionGateway is found. The original developer had this method to make the subscription:

```auto
def tag_subscribe(path, listener):
	tp = TagPathParser.parse(path)
	IgnitionGateway.get().getTagManager().subscribe(tp, listener)
	return (tp, listener)

```

Thanks,

Rick

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2019, 2:04pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/11 "2019-05-16T14:04:28Z")

</div>

TagManager’s API has changed. You’re venturing into Module SDK territory at this point.

It would probably be best to create a new topic for this. I’m not sure if what you’re doing is even safe 😬

---

<div class="post-metadata">

**Author:** ![rttwge](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rttwge](https://forum.inductiveautomation.com/u/rttwge)\
**Post date:** [May 16, 2019, 2:12pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/12 "2019-05-16T14:12:03Z")

</div>

🙂 Ya, what I didn’t post was the original developer said, and I paraphrase … “shakey territory”

I did find the documentation on TagManager this and it seems subscribe is gone, as the error indicates, but subscribeAsync is available. I’ll give it a shot and report back.

Thanks … helps to talk this through - in public no less 🙄

-Rick

---

<div class="post-metadata">

**Author:** ![rttwge](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rttwge](https://forum.inductiveautomation.com/u/rttwge)\
**Post date:** [May 17, 2019, 4:34am UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/13 "2019-05-17T04:34:47Z")

</div>

So reporting back, IgnitionGateway does of course work and instead of .subscribe, .subscribeAsync should be used. There are two overloads of subscribeAsync, the one taking one path and one listener must be private because it is not recognized, so I used the list version that has the two "list" parameters required (list of tags, list of listeners).

The TagChangeListener I used is from com.inductiveautomation.ignition.common.tags.model.event ... like this

> from com.inductiveautomation.ignition.common.tags.model.event import TagChangeListener

Here is the top portion of my handler

```auto
class HandshakeListener(TagChangeListener):
	def __init__ (self, parent):
 		self.__parent = parent
	def tagChanged(self, event):
		objValue = event.getValue()
		value = objValue.getValue()

```

Notice above I've broken out to values ... objValue represents an object with multiple properties, one of which is value. To get "the value" of the tag, call get getValue() on the the event object value.

-Rick

---

<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 17, 2019, 11:56am UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/14 "2019-05-17T11:56:59Z")

</div>

I sure hope you are keeping track of these (this?) listeners with the system.util.getGlobals() dictionary -- otherwise you will be attaching code to platform objects that will survive code edits and will leak jython interpreters along the way. See this discussion:

> [@\[REQUEST\] Persistence of an object instance after Scripting Save](http://forum.inductiveautomation.com/t/request-persistence-of-an-object-instance-after-scripting-save/23641/4):
>
> In order to pick up new/changed jython code in importable script modules, Ignition must start a new interpreter with scopes for each project and for the global scripting project. The first call into a script module after interpreter startup imports it, creating all top-level named objects in the script module (functions, classes, and module-scope variables). All jython objects referenced solely by the old interpreters are garbage collected with the interpreter. Any old jython objects (code or…

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [April 16, 2020, 7:02am UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/15 "2020-04-16T07:02:06Z")

</div>

Hi, was this renamed again?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/db5626e4d11053b5f050b1a14890782e948b95da.png)  
v8.0.9

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 16, 2020, 12:02pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/16 "2020-04-16T12:02:39Z")

</div>

No, it’s just only accessible in Gateway scope, and you’re in Designer scope in the script console.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [April 16, 2020, 5:58pm UTC](https://forum.inductiveautomation.com/t/how-to-get-gatewaycontext-in-gateway-event-timer-script/24668/17 "2020-04-16T17:58:18Z")

</div>

ops, Thanks @Kevin.Herron
