# Access Tag Reference Tracker by Script

**URL:** <https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943>\
**Category:** Ignition\
**Created:** [October 30, 2024, 9:49am UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943 "2024-10-30T09:49:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [October 30, 2024, 9:49am UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/1 "2024-10-30T09:49:01Z")

</div>

Is it possible to retrieve the Tag Reference Tracker log in the script?  
Right now KI only can access this info from the designer tag diagnostic.  
It will be really handy for searching.

---

<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:** [October 30, 2024, 3:32pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/2 "2024-10-30T15:32:11Z")

</div>

There's no supported/exposed way to retrieve the information from the tag reference tracker, but like most things in Ignition, it's still _possible_.  
I would recommend doing this on the gateway, but if you've got a gateway context already, then something like this:

```python
from com.inductiveautomation.ignition.common.tags.config.model import TagReferenceQuery
from com.inductiveautomation.ignition.common.tags.paths import BasicTagPath

# @param activeSubscriptions True, only return references from current subscriptions to tag. False, returns all other stored references.
# @param activeSince References where the most recent activity occurred before [activeSince] will be filtered from results. 0, to ignore and return all references.
query = TagReferenceQuery(
	BasicTagPath("default", "path/to/tag".split("/")),
	False, #activeSubscriptions
	0 #activeSince
)

references = context.tagManager.getTagProvider("default").getTagReferences(query).get()

```

---

<div class="post-metadata">

**Author:** ![sherman](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@sherman](https://forum.inductiveautomation.com/u/sherman)\
**Post date:** [March 27, 2025, 4:33am UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/3 "2025-03-27T04:33:48Z")

</div>

~~Sorry if this is something that I should know, but I hit this when I run that script (with tag provider and tag path arranged): `NameError: global name 'context' is not defined`~~  ~~Its in the module development environment I see. I don't know how to use that quite yet.~~ Alright I figured out how to get it in a messageHandler and read out in the gateway logs. It is cumbersome.

Is there a "gateway scoped" script console? I tried running this is a message handler but I got the same error. I think I know that there is not but I want to double check

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 27, 2025, 10:44am UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/4 "2025-03-27T10:44:49Z")

</div>

> [@sherman](#):
>
> Is there a "gateway scoped" script console?

There is not.

If you have Phil’s Toolkit module it includes a decorator that will cause functions to be run in Gateway Scope, if you can’t go that route then the best you can do is a Gateway Message handler

---

<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:** [March 27, 2025, 2:23pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/5 "2025-03-27T14:23:46Z")

</div>

> [@lrose](#):
>
> the best you can do

IMO, clicking a button in Perspective is easier, because you can at least keep the script editing window open/floating and just apply your changes to fire it off.

We have plans to add a 'Gateway Script Console', probably at some point in the 8.3 lifecycle.

---

<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:** [March 27, 2025, 2:32pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/6 "2025-03-27T14:32:08Z")

</div>

> [@paul-griffith](#):
>
> a 'Gateway Script Console',

This makes me cringe. Please **audit** anything run from such a thing. My decorator only works on code in a project that is **saved** , which is auditable.

---

<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:** [March 27, 2025, 2:38pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/7 "2025-03-27T14:38:10Z")

</div>

🤷  
I agree with you in principle, but as this thread points out, means to get the gateway to run arbitrary code (even not yet formally saved code) via the designer abound. What I _will_ probably push for is a means to opt-out of the feature entirely. Thinking out loud, that opt-out may (need to) also apply to e.g. Perspective in the Designer's use of not-yet-saved scripting changes.

---

<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:** [March 27, 2025, 2:40pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/8 "2025-03-27T14:40:38Z")

</div>

> [@paul-griffith](#):
>
> Perspective in the Designer's use of not-yet-saved scripting

Well, that security/audit hole can be closed by leaving Perspective out of the system. 😬

_/me runs away_

> [@paul-griffith](#):
>
> run arbitrary code (even not yet formally saved code) via the designer abound

It would be good to enumerate them all in the docs. Tag config (scripts) are audited now-a-days, aren't they?

---

<div class="post-metadata">

**Author:** ![sherman](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@sherman](https://forum.inductiveautomation.com/u/sherman)\
**Post date:** [March 28, 2025, 10:03pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/9 "2025-03-28T22:03:48Z")

</div>

Ah I do not use perspective but I understand it runs entirely in the gateway, so that makes sense. I have to use the cumbersome messageHandler -\> gateway log route and it really hurts my iteration time.

---

<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:** [March 28, 2025, 10:15pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/10 "2025-03-28T22:15:47Z")

</div>

> [@sherman](#):
>
> messageHandler -\> gateway log route

_\*Cough\*_

`system.util.runInGateway()`

---

<div class="post-metadata">

**Author:** ![sherman](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@sherman](https://forum.inductiveautomation.com/u/sherman)\
**Post date:** [March 28, 2025, 10:31pm UTC](https://forum.inductiveautomation.com/t/access-tag-reference-tracker-by-script/97943/11 "2025-03-28T22:31:27Z")

</div>

Yes I will have to add your integration toolkit once I finish this project
