# Relative Tag Paths with queryTagHistory Function

**URL:** <https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185>\
**Category:** Ignition\
**Tags:** perspective, scripting, ignition81\
**Created:** [May 9, 2024, 7:33pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185 "2024-05-09T19:33:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![M.O](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@M.O](https://forum.inductiveautomation.com/u/M.O)\
**Post date:** [May 9, 2024, 7:33pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/1 "2024-05-09T19:33:49Z")

</div>

Hello, I am attempting to call queryTagHistory() within the Value Changed script of TagA, to find the history of TagB which resides in the same folder.

This logic will be applied to other tag trees so it needs to reference the relative tag path `"[.]TagB"` when getting historical data.

This seems simple enough, but I'm wondering if maybe I am doing something wrong syntactically. Here is the script for Value Changed for tag A

```python
endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -1)
dataSet = system.tag.queryTagHistory(paths=["[.]TagB"], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Range", returnFormat='Wide')

logger.info(str(dataSet.getValueAt(0,1)))

```

The logger returns "None" in this instance. But, when I use the very same relative tag path in readBlocking(), the tag data is returned.

```python
tagValue = system.tag.readBlocking(["[.]TagB"])
logger.info(str(tagValue))

```

Here, the logger returns [[1234567, Good, Thu May 09 14:11:33 CDT 2024 (1715281893803)]] so I know it is getting the right value.

I also tested my same queryTagHistory call with the full path name for TagB instead of the relative path name and I get the correct historical data I am looking for.

```python
dataSetFullPath = system.tag.queryTagHistory(paths=["[provider]path1/path2/path3/TagB"], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Range", returnFormat='Wide')

logger.info(str(dataSetFullPath.getValueAt(0,1)))

```

Accurately yields a valid number.

Would anyone be able to weigh in on why `system.tag.queryTagHistory(paths=["[.]TagB"], ...` would not work but `system.tag.readBlocking(["[.]TagB"])` does? Thank you in advance

---

<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 9, 2024, 7:37pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/2 "2024-05-09T19:37:32Z")

</div>

> [@M.O](#):
>
> queryTagHistory() within the Value Changed script of TagA

That is an **extremely** bad idea. Tag valueChange scripts must execute **very** quickly--single digit millis or less--or you can bog down all tag events. History queries are definitely not acceptable. (Nor any other database operations, nor any tag/opc operations that reach out over the network.)

What do you need to do this for, really?

---

<div class="post-metadata">

**Author:** ![M.O](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@M.O](https://forum.inductiveautomation.com/u/M.O)\
**Post date:** [May 9, 2024, 7:42pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/3 "2024-05-09T19:42:57Z")

</div>

TagA is an expression tag that would have a fixed execution rate of 1 min, its job is to get the value of historized TagB from 1 minute ago and compare it to the current value.

I am not necessarily dead set on using the Value Changed, I was more or less just testing out that I could get the value of TagB from 1 minute ago and do some scripting on that value, which led me here. Any suggestions you may have on how to accomplish this would be appreciated.

---

<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 9, 2024, 7:49pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/4 "2024-05-09T19:49:55Z")

</div>

I recommend using a scheduled event that runs at the top of the minute. Have its script pull the appropriate history in one go for all the tags that need this kind of processing.

---

<div class="post-metadata">

**Author:** ![M.O](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@M.O](https://forum.inductiveautomation.com/u/M.O)\
**Post date:** [May 9, 2024, 7:57pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/5 "2024-05-09T19:57:45Z")

</div>

If I use a scheduled event, that doesn't solve my problem for needing to write out the entire tag path, correct? This is logic that will need to be expandable to several paths even within the same project, so the path would need to be relative.

---

<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 9, 2024, 8:40pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/6 "2024-05-09T20:40:41Z")

</div>

No, the script would have a constant list of all of the absolute tag paths.

---

<div class="post-metadata">

**Author:** ![M.O](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@M.O](https://forum.inductiveautomation.com/u/M.O)\
**Post date:** [May 10, 2024, 1:47pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/7 "2024-05-10T13:47:32Z")

</div>

> [@pturmel](#):
>
> That is an **extremely** bad idea. Tag valueChange scripts must execute **very** quickly--single digit millis or less--or you can bog down all tag events. History queries are definitely not acceptable.

Would this be the reason that the relative tag path would not work for queryTagHistory?

```python
system.tag.queryTagHistory(paths=["[.]TagB"], ...

```

Is this syntax not acceptable for the function?  
It works fine with the full tag path and `system.tag.readBlocking(["[.]TagB"])` shows that it is a valid relative path.

---

<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:** [May 10, 2024, 2:40pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/8 "2024-05-10T14:40:28Z")

</div>

I believe @pturmel is saying that he is completely against using the queryTagHistory function at all in valueChanged event. Even if it did work, your next post on the forums would be "Why is my gateway performing so badly/slowly". He's suggesting other ways of accomplishing what you're wanting to do.

With that being said, there's alternate ways to get the full path without using relative referencing since the tagPath is passed in as a parameter of the event/function, but again, take @pturmel's advice as he's very experienced at what he does. Outside of the Inductive Automation staff, he's the top contributor to these forums.

---

<div class="post-metadata">

**Author:** ![M.O](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@M.O](https://forum.inductiveautomation.com/u/M.O)\
**Post date:** [May 10, 2024, 2:56pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/9 "2024-05-10T14:56:22Z")

</div>

That's no problem, I can find a different way of going about this. I was more or less still curious about my original question and why this call wasn't working. Either way, I'd take yours and @pturmel 's advice here.

Thank you

---

<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 10, 2024, 4:09pm UTC](https://forum.inductiveautomation.com/t/relative-tag-paths-with-querytaghistory-function/90185/10 "2024-05-10T16:09:59Z")

</div>

> [@M.O](#):
>
> Is this syntax not acceptable for the function?

This. Relative paths are only applicable in tag events and expression tags, neither of which is an acceptable place to call history.
