# Get the Historical Tag Path from the Tag Path

**URL:** <https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 16, 2022, 5:27pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981 "2022-07-16T17:27:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISEMAREN\_AAG](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@ISEMAREN\_AAG](https://forum.inductiveautomation.com/u/ISEMAREN_AAG)\
**Post date:** [July 16, 2022, 5:27pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/1 "2022-07-16T17:27:45Z")

</div>

Good afternoon.

I would like to know if it is possible to obtain the **Historical Tag Path from the Tag Path**.

For example, if I know the Tag Path is “simulator/turbine 3”, I would like to get its Historical Tag Path **automatically** : ''histprov:DB:/drv:controller:default:/tag:simulator/turbine 3", without need to build the text string cocatenating the different elements that compose it.  
Is there a function that returns the Historical Tag Path?

Best Regards.

---

<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 17, 2022, 7:38am UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/2 "2022-07-17T07:38:19Z")

</div>

Here you go:

> [@Get historical path from tagpath](https://forum.inductiveautomation.com/t/get-historical-path-from-tagpath/59128/10):
>
> from com.inductiveautomation.ignition.common import QualifiedPath, WellKnownPathTypes qp = QualifiedPath.Builder() .set(WellKnownPathTypes.HistoryProvider, "provider") .setDriver("driver") .setTag("path/to/tag") .build() .toString() Doesn’t really buy you much over joining the string parts together yourself.

---

<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:** [July 17, 2022, 9:06am UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/3 "2022-07-17T09:06:49Z")

</div>

@lrose Not sure that helps as there could be multiple drivers/providers and Paul’s method creates them as static. Although once you know the parts you could use this to create the path. Might have to read all of the parts from the tag itself. Not sure if there’s another way

---

<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 17, 2022, 1:39pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/4 "2022-07-17T13:39:41Z")

</div>

@nminchin I agree but it the only method I know of that isn’t concatenation the parts together.

Perhaps combining this with pulling the tag configuration?

---

<div class="post-metadata">

**Author:** ![ISEMAREN\_AAG](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@ISEMAREN\_AAG](https://forum.inductiveautomation.com/u/ISEMAREN_AAG)\
**Post date:** [July 17, 2022, 11:02pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/5 "2022-07-17T23:02:21Z")

</div>

Good night.

I’ve thought about using the "**system.tag.getConfiguration()"** function, but of all the elements I need to build the Historical Tag Path, that function only gives me the history provider. I don’t understand why that function doesn’t provide the Gateway and TagProvider of a tag. It would be ideal.  
So I’ll build the Historical Tag Path by concatenating its parts.

---

<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 18, 2022, 6:09pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/6 "2022-07-18T18:09:01Z")

</div>

So, the driver is actually part of the full tag path. It is possible if you are using remote tag providers to use a gateway message handler in conjunction with this function to get what you’re looking for.

If you put this function in a shared script on the same gateway as the tag provider, then it should return your historical tag path.

Inspired heavily from the script provided by @paul-griffith

```python
def getHistoricalTagPath(path):
    from com.inductiveautomation.ignition.common import QualifiedPath, WellKnownPathTypes,QualifiedPathUtils
    from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser

    qPath = QualifiedPathUtils.fromTagPathNew(TagPathParser.parseSafe('default',path))
    histProv, gateway = system.tag.readBlocking([path + '.historyProvider','[System]Gateway/SystemName'])
    driver = ':'.join([gateway.value,qPath.getPathComponent('prov')])
    return QualifiedPath.Builder().set(WellKnownPathTypes.HistoryProvider,histProv.value).setDriver(driver).setTag(qPath.getPathComponent('tag')).build().toString()

```

So using the following assumptions:

1. The system name of the gateway this function is run on is `controller`
2. The historical provider of the tag is set to `DB`
3. You provide the path `'[default]simulater/turbine 3'` or `'simulater/turbine 3'`

Then this function will return `histprov:DB:/drv:controller:default:/tag:simulater/turbine 3`

You could also just hard code the gateway in if it isn’t going to change often.

I chose to use `system.tag.readBlocking()` here because `system.tag.getConfiguration()` only returns non-default properties, since a historical provider is not provided by default it should always be returned, but better safe than sorry. Also, I needed to call the function anyway to get the gateway name, so just as easy to get it from there.

You may want to consider either verifying that history is enabled for the provided path, or coalescing to a default if a ‘historical provider’ is not provided.

If you take out the `toString()` and instead return just a QualifiedPath then you could use this function to do a lot of things, for instance checking for incorrect configurations.

```auto
print [tag['fullPath'] for tag in system.tag.browse('path/to/folder',{'tagType':'Atomic Tag'}).getResults() if getHistoricalTagPath(tag['fullPath']).getPathComponent('prov') in ('null','SomeOtherIncorrectProvider')]

```

---

<div class="post-metadata">

**Author:** ![tmahaf](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaf/32/23492_2.png) [@tmahaf](https://forum.inductiveautomation.com/u/tmahaf)\
**Post date:** [October 22, 2024, 4:19pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/7 "2024-10-22T16:19:42Z")

</div>

Call me lazy but I'm pretty annoyed that Ignition can't do that on its own.

---

<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 22, 2024, 8:05pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/8 "2024-10-22T20:05:12Z")

</div>

I agree also that there should be a stock function that builds this for you without going through hoops

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 22, 2024, 8:52pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/9 "2024-10-22T20:52:55Z")

</div>

I’m not sure how it could do that.  
I’m doing a complex history system right now, with A LOT of different providers, some remote and some not, and as many different drivers.  
Some tags could be historized in more than one historian, some entries could be “virtual”, by which I mean they’re not related to an actual tag.  
The best you can do is use the historian drivers table to “automatically” build paths.  
But if you want to find the history paths for a tag, you’ll still need to somehow link the drivers to the tag providers (which is not obvious in the case of a remote provider, since the driver will use the name of the provider on the gateway where it lives).  
All of that to say it’s not as simple as mapping one path to another.

---

<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 22, 2024, 9:04pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/10 "2024-10-22T21:04:01Z")

</div>

> [@pascal.fragnoud](#):
>
> which is not obvious in the case of a remote provider, since the driver will use the name of the provider on the gateway where it lives

See this topic:

> [@Remote Tag Provider History Queries](https://forum.inductiveautomation.com/t/remote-tag-provider-history-queries/93632):
>
> I'm working on a couple tasks related to historians and history queries, and have encountered some behaviors of remote tag providers (RTPs) that have me stymied: There's no public way to retrieve the gateway name that a RTP is pointing at, nor any public way to retrieve the far end's real tag provider name. (Reflection has exposed com.inductiveautomation.ignition.gateway.tags.distributed.client.RemoteTagProvider and com.inductiveautomation.metro.api.ServerId to me, and a number of private fie…

Agreed, not obvious. But not difficult. (See example code.)

---

<div class="post-metadata">

**Author:** ![tmahaf](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaf/32/23492_2.png) [@tmahaf](https://forum.inductiveautomation.com/u/tmahaf)\
**Post date:** [October 22, 2024, 9:49pm UTC](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/11 "2024-10-22T21:49:10Z")

</div>

The gateway would have to find out through a series of calls to the tag provider's remote gateway until if finds the Realtime Tag Provider that is not a "Remote Tag Provider", from there it can generate the system name, drvid, scid, all of that.
