# system.tag.queryTagHistory can't access the tag created by system.tag.storeTagHistory

**URL:** <https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [April 28, 2025, 4:13pm UTC](https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637 "2025-04-28T16:13:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haniyeh\_Seyed\_Alinez](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@Haniyeh\_Seyed\_Alinez](https://forum.inductiveautomation.com/u/Haniyeh_Seyed_Alinez)\
**Post date:** [April 28, 2025, 4:13pm UTC](https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637/1 "2025-04-28T16:13:41Z")

</div>

Hi every one,

I use this code to store " **data**" (which is a real-time calculated value) as a history tag (tag5):

```python
paths = ["folder/tag5"]
system.tag.storeTagHistory(histProv, tagProv, paths, data)

```

Then I try to query the created history tag's values using this:

```python
endTime = system.date.now()
startTime = system.date.addHours(endTime, -24)
Hist_Tag_Paths = ["[tagProv]folder/tag5"]
Cols = ["data_query"]
result = system.tag.queryTagHistory(paths=Hist_Tag_Paths,
startDate=startTime, endDate=endTime, returnSize=0, aggregationMode="Average", returnFormat='Wide', columnNames = Cols)

```

I have also added tag5 as a pen to a PowerChart and I can see its values plotted as a graph, but the " **result**" returned by `system.tag.queryTagHistory` is an empty dataset.

Does anyone have any idea why `system.tag.queryTagHistory` can't find this history tag?

Thanks

---

<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:** [April 28, 2025, 4:41pm UTC](https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637/2 "2025-04-28T16:41:09Z")

</div>

Does the tag exist? And have history turned on?

(`.storeTagHistory()` is not intended to be the primary path to store history, but is a tool to backfill missing history for a tag that otherwise records normally.)

---

<div class="post-metadata">

**Author:** ![Haniyeh\_Seyed\_Alinez](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@Haniyeh\_Seyed\_Alinez](https://forum.inductiveautomation.com/u/Haniyeh_Seyed_Alinez)\
**Post date:** [April 28, 2025, 5:13pm UTC](https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637/3 "2025-04-28T17:13:39Z")

</div>

> [@pturmel](#):
>
> And have history turned on?

This was the issue. I enabled the tag's history and now I can get the values using `system.tag.queryTagHistory`.

Thank you for your help @pturmel

---

<div class="post-metadata">

**Author:** ![Haniyeh\_Seyed\_Alinez](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@Haniyeh\_Seyed\_Alinez](https://forum.inductiveautomation.com/u/Haniyeh_Seyed_Alinez)\
**Post date:** [April 28, 2025, 9:04pm UTC](https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637/4 "2025-04-28T21:04:11Z")

</div>

Another issue I’ve noticed with this implementation is that when the Designer or any session is not open, the script does not seem to historize data to tag5 properly — likely because it is not being executed at all.

The script is designed to run in real time as a transform on an expression binding to a main view parameter (see attached screenshot). It calculates the "data" value using `system.tag.queryTagCalculations` based on another history tag’s values, and then stores the result to tag5 as described earlier.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/f/bf1f4ff4ab4e441f45ed0d8484d164b8de657722.png)

Any idea regarding this is appreciated

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [April 28, 2025, 9:25pm UTC](https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637/5 "2025-04-28T21:25:32Z")

</div>

> [@Haniyeh\_Seyed\_Alinez](#):
>
> likely because it is not being executed at all.

Correct, if its a binding on a view then it's not being run if there is no session. It also means it's being run on EVERY session that is open. Tha's probably filling your history with a bunch of duplicates.

> [@Haniyeh\_Seyed\_Alinez](#):
>
> which is a real-time calculated value

Make an expression tag that calculates this value and enable history on that tag. Or if the calculation is too complex for an expression, make a gateway timer event and do the calculation in there.

---

<div class="post-metadata">

**Author:** ![Haniyeh\_Seyed\_Alinez](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@Haniyeh\_Seyed\_Alinez](https://forum.inductiveautomation.com/u/Haniyeh_Seyed_Alinez)\
**Post date:** [April 28, 2025, 9:32pm UTC](https://forum.inductiveautomation.com/t/system-tag-querytaghistory-cant-access-the-tag-created-by-system-tag-storetaghistory/105637/6 "2025-04-28T21:32:51Z")

</div>

Thanks for your response, Ryan.

I initially wanted to implement the calculation as an expression tag, but my calculation requires taking the average of historical values over a predefined period. I couldn’t find a way to do this with an expression tag, as it seems expression tags don’t support historical queries — or at least I'm not aware of a way to accomplish it.

Using a gateway timer script is a great idea. Thank you for the suggestion!
