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

Hi everyone,

I tested a script in the scripting console.

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):

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:

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

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

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

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.