# Pulling value from history enabled tag, improper practice or error?

**URL:** <https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643>\
**Category:** Ignition\
**Created:** [December 10, 2024, 5:38pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643 "2024-12-10T17:38:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![D\_Mitri\_Tompkins](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@D\_Mitri\_Tompkins](https://forum.inductiveautomation.com/u/D_Mitri_Tompkins)\
**Post date:** [December 10, 2024, 5:38pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643/1 "2024-12-10T17:38:21Z")

</div>

I have a history enabled tag, I am attempting to write a script to print the value the tag has currently, as well as the value it had earlier in the day. However, the value for earlier always is returned as "None" though I am certain there is data available. The code I am using is as follows

```python
def retailCompare():
    eight_hours_ago = system.date.addHours(system.date.now(), -8)

    tag_path = system.tag.readBlocking("[default]tagnamechangedforprivacyisuppose")
    history = system.tag.queryTagHistory(paths=[tag_path],
                                        startDate = system.date.addHours(system.date.now(), -8),
                                        endDate = system.date.now(),
                                        returnSize = 1,
                                        aggregationMode = "Minimum",
                                        returnFormat = "Wide",)

    if history:
          	value = history.getValueAt(0,1)
          	value1 = tag_path[0].value
    print(value)
    print(value1)

```

This code when ran in the script console returns:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/c/dcc1aa04fe7114a1bc749292e1e83e3883117052.png)  
I can accurately pull the timestamp value at any time, but can't pull the value value unless I am accessing it's current value, what am I doing wrong?

---

<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:** [December 10, 2024, 5:42pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643/2 "2024-12-10T17:42:47Z")

</div>

You aren't passing a tag path to your history query, but the result of the readBlocking--a list of QVs. So the history query will look up the stringified version of that list as though it is a tag path, and won't find it, yielding null. (Look at the column name for that in the history dataset to see what I mean.)

Don't use the variable name `tagpath` for something that isn't a tag path.

---

<div class="post-metadata">

**Author:** ![D\_Mitri\_Tompkins](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@D\_Mitri\_Tompkins](https://forum.inductiveautomation.com/u/D_Mitri_Tompkins)\
**Post date:** [December 10, 2024, 5:50pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643/3 "2024-12-10T17:50:13Z")

</div>

So it should be:

```python
history = system.tag.queryTagHistory("[default]CWS Retail/Bag Check Weigh - Line 5/Statistics/Current/Batch/Total Accepted Count"), startDate = , endDate =

```

And that should get me the actual value of the tag?

Also my apologies, I thought it was good practice to define tag paths like I did above, is that true for cases other than this or just generally not true to do so?

---

<div class="post-metadata">

**Author:** ![D\_Mitri\_Tompkins](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@D\_Mitri\_Tompkins](https://forum.inductiveautomation.com/u/D_Mitri_Tompkins)\
**Post date:** [December 10, 2024, 5:54pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643/4 "2024-12-10T17:54:20Z")

</div>

Okay yep changed that and it now works as expected, thank you.

I think I was erroneously following the docs for `system.tag.queryTagCalculations` where I mistook it using `system.tag.queryTagCalculations(paths=['Historical Tag']`

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:** [December 10, 2024, 5:57pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643/5 "2024-12-10T17:57:59Z")

</div>

> [@D\_Mitri\_Tompkins](#):
>
> good practice to define tag paths

Sure, put tag paths (strings) into python variables. Reference them by varname in the multiple places needed.

I tend to use variations of `qvList` as the assignment name for the return value from any `readBlocking()` call, to remind me what its structure is.

---

<div class="post-metadata">

**Author:** ![D\_Mitri\_Tompkins](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@D\_Mitri\_Tompkins](https://forum.inductiveautomation.com/u/D_Mitri_Tompkins)\
**Post date:** [December 10, 2024, 5:58pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643/6 "2024-12-10T17:58:38Z")

</div>

Potentially dumb followup here, I can now simply write this value to a new tag using `system.tag.writeBlocking([path],[oldvalue])` and then enable history on it right?

---

<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:** [December 10, 2024, 5:59pm UTC](https://forum.inductiveautomation.com/t/pulling-value-from-history-enabled-tag-improper-practice-or-error/99643/7 "2024-12-10T17:59:50Z")

</div>

> [@D\_Mitri\_Tompkins](#):
>
> and then enable history on it right?

That makes no sense to me. But try it.
