# Tag Event Script system.tag.queryHistory only writes NULL inside UDT but scripting console is working

**URL:** <https://forum.inductiveautomation.com/t/tag-event-script-system-tag-queryhistory-only-writes-null-inside-udt-but-scripting-console-is-working/66851>\
**Category:** Ignition\
**Created:** [November 23, 2022, 1:32pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-system-tag-queryhistory-only-writes-null-inside-udt-but-scripting-console-is-working/66851 "2022-11-23T13:32:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eike\_Saathoff](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Eike\_Saathoff](https://forum.inductiveautomation.com/u/Eike_Saathoff)\
**Post date:** [November 23, 2022, 1:32pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-system-tag-queryhistory-only-writes-null-inside-udt-but-scripting-console-is-working/66851/1 "2022-11-23T13:32:04Z")

</div>

Hi everyone,

I tested a script in the scripting console.

```auto
pathStatus = "[Staging]TEST/ABC/Line1/MachineA/_intern/DurationTag"
dayStart = [Staging]Intern/Time/dayStart
dayEnd = [Staging]Intern/Time/dayEnd
result = system.tag.queryTagHistory(paths=[pathStatus], startDate=dayStart, endDate=dayEnd, aggregationMode="DurationOn", returnSize=1)
resultTime = result.getValueAt(0,1)
system.tag.writeBlocking(["[STAGING]TEST/ABC/Line1/MachineA/_intern/TimeTag"],[resultTime])

```

In the scripting console it worked like a charm.

Now I inserted it inside of my UDT and the only thing I changed were the paths from pathStatus and the tag I want to write to in my writeBlocking to the UDT related paths (want to use it inside every instance of my UDT):

```auto
pathStatus = "[.]DurationTag"
tagBeginn = ...
tagEnde = ...
result = system.tag.queryTagHistory(paths=[pathStatus], startDate=tagBeginn, endDate=tagEnde, aggregationMode="DurationOn", returnSize=1)
resultTime = result.getValueAt(0,1)
system.tag.writeBlocking(["[.]TimeTag"],[resultTime])

```

But it is not working anymore... It only writes "null" inside the "TimeTag" of every instance. And I didn't change anything but the two paths. Since the first version (without UDT paths) is working inside of the UDT, nothing is wrong with the tag event script execution. I also tested a static value and it worked. My guess is, that the system.tag.query.TagHistory query is not returning anything but why is it working in the scripting console?

Update: When I try to cast the result on int() I get the following error message:

```auto
Error executing script.
Traceback (most recent call last):
  File "<tagevent:valueChanged>", line 7, in valueChanged
TypeError: int() argument must be a string or a number, not 'None'

```

Greetings and thanks in advance

---

<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:** [November 23, 2022, 2:15pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-system-tag-queryhistory-only-writes-null-inside-udt-but-scripting-console-is-working/66851/2 "2022-11-23T14:15:53Z")

</div>

Well try in your scrip console with the same path and see if you get results.  
edit: check the result of

```python
result
for c in xrange(result.getColumnCount()):
	for r in xrange(result.getRowCount()):
		r, c
		ds.getValueAt(r, c)

```

---

<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:** [November 23, 2022, 7:24pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-system-tag-queryhistory-only-writes-null-inside-udt-but-scripting-console-is-working/66851/3 "2022-11-23T19:24:35Z")

</div>

It seems that `system.tag.queryTagHistory()` is not correctly resolving the relative tag path.

Since you have said you tested it with the full path and it worked, I suspect you may need to use a UDT parameter to build the full tag path to the DurationTag.
