# Remote Tag Provider History Queries

**URL:** <https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [July 23, 2024, 8:17pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632 "2024-07-23T20:17:15Z")\
**Posts on this page:** 11\
**Page:** 2

<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:** [July 25, 2024, 4:57pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/21 "2024-07-25T16:57:12Z")

</div>

No. Given an RTP name or RTP object, **something** has to cough up a gateway name. How would you know what IP to point that URL at?

---

<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:** [July 25, 2024, 5:04pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/22 "2024-07-25T17:04:10Z")

</div>

Makes me wonder how difficult it would be to write a message function that broadcasts to all servers on the GAN, as opposed to assuming the local server unless a remote server is provided.

hmmm....

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [July 25, 2024, 5:22pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/23 "2024-07-25T17:22:02Z")

</div>

What about automating the documentation by having a couple of tags in the remote provider that are auto-populated (not sure what the best trigger would be to be honest) with the originating gateway's name and real provider name?

Still a hack but hopefully a little less error-prone that way. The trigger is kind of an issue though because if someone renames the upstream provider we want to know about it right away.

---

<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:** [July 25, 2024, 5:36pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/24 "2024-07-25T17:36:01Z")

</div>

My plan is to use reflection on the non-public fields for now, and agitate for a public API in v8.3. This is for a generic utility (coming to the Exchange soon) for which such work-arounds are not really appropriate.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 25, 2024, 9:01pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/25 "2024-07-25T21:01:48Z")

</div>

Well, if 8.3 does have a full RESTful API, then I would think you could get everything you need even if it is just communicating with itself to grab the data (although it wouldn't be as efficient as being able to pull it directly via a script).

---

<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:** [July 25, 2024, 9:02pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/26 "2024-07-25T21:02:30Z")

</div>

Good point.

---

<div class="post-metadata">

**Author:** ![msteele](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/msteele/32/77889_2.png) [@msteele](https://forum.inductiveautomation.com/u/msteele)\
**Post date:** [July 25, 2024, 9:16pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/27 "2024-07-25T21:16:42Z")

</div>

Could you just inject a custom property string inside the realtime tag provider's tags, then read its value over the gateway network?  
Edit nvm that looks like what @Felipe_CRM suggested upthread.

---

<div class="post-metadata">

**Author:** ![James.Sletten](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@James.Sletten](https://forum.inductiveautomation.com/u/James.Sletten)\
**Post date:** [August 2, 2024, 9:20pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/28 "2024-08-02T21:20:51Z")

</div>

I just ran into this issue this afternoon and came up with the following solution for my application. This runs as a script transform on an expression binding.

I query the database tables in the historian to collect the required info an use that to concatenate a historical tag path.

This script produces this path as an output. histprov:HistDB:/drv:Site\_023:edge:/tag:gln/gln\_lit\_051\_li/ind pv

```python
		# Query the historian database tables for required information.
		query = """
			SELECT TOP 1
				te.tagpath,
				drv.name AS driver_name,
				drv.provider as provider
			FROM 
			    sqlth_te AS te
			JOIN 
			    sqlth_scinfo AS scinfo ON te.scid = scinfo.id
			JOIN 
			    sqlth_drv AS drv ON scinfo.drvid = drv.id
			WHERE 
			    te.tagpath = ?
			"""
	
		# Get default DB connection for this project. 
		database = system.db.getConnectionInfo().getValueAt(0, "name")
		
		# Execute query against the default DB for this project. Replace tag path with your own. I use a custom property to pass the tag just showing it as an example. 
		results = system.db.runPrepQuery(query, ['GLN/GLN_LIT_051_LI/ind pv'], database)
		
		# Extract driver name and provider from query result. 
		drive_name = results.getValueAt(0,'driver_name')
		provider = results.getValueAt(0,'provider')
		tagpath = results.getValueAt(0,'tagpath')
		
		#Concatenate tag history path. 
	  	return 'histprov:' + database + ':/drv:'+drive_name + ':' + provider + ':/tag:'+ tagpath

```

---

<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:** [September 4, 2024, 6:12pm UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/29 "2024-09-04T18:12:45Z")

</div>

> [@pturmel](#):
>
> This is for a generic utility (coming to the Exchange soon)

Over here, BTW:

> [@Tag Report Utility](https://forum.inductiveautomation.com/t/tag-report-utility/95299):
>
> New resource just uploaded to the Exchange (pending review). Also available here: [https://www.automation-pros.com/TagReportUtility/](https://www.automation-pros.com/TagReportUtility/) I intend to publish at this link as well as in the Exchange going forward. Announcements will be in this topic. (: Highlights: Provides a Perspective Popup View that provides a user interface to system.tag.query() that entirely replicates the functionality of the Designer's Tag Report Tool. Provides a Perspective Embedded View that provides Time Span selectio…

---

<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:** [October 23, 2024, 2:51am UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/30 "2024-10-23T02:51:11Z")

</div>

At a risk of sounding stupid...  
The historical tag provider originating connection names _are_ stored in the internal DB. Could you cache this? Obviously using an API method to get this would be better, but in a pinch..

> [@\[FEATURE\] Adding pens to ad-hoc to a trend - Missing exposure to functions needed](https://forum.inductiveautomation.com/t/feature-adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432/2):
>
> E.g. using a super dodgy query on the internal db... tagPath = 'Tag/Path' # get the tag provider in the local gateway from the config in case the tag provider wasn't provided in the path tagProvider = system.tag.getConfiguration(tagPath)[0]['path'].split(']')[-1] context = system.util.getContext() session = context.getPersistenceInterface().getSession() try: query = """ SELECT COALESCE(gtps.PROVIDERNAME, tps.NAME) as tag\_provider, gtps.HISTORYDRIVERNAME as gateway\_name FROM TAGPROVI…

---

<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:** [October 23, 2024, 11:32am UTC](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632/31 "2024-10-23T11:32:34Z")

</div>

Meh. If given the choice between reflection and touching the internal DB, I'm going to use reflection every time.

[Previous page](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632.md?page=1)
