queryTagHistory returning empty datasets

I'm struggling to retrieve any historized tag data through system.tag.queryTagHistory. I have tried a number of different parameter combinations in the function call, and the returned dataset either:

  • Contains all None values in the column representing the tag values if I force a specific returnSize
  • Contains no rows if I don't specify a returnSize

I know there are historized values within this date range because I have checked the relevant sqlt_data tables using the Database Query Browser.

The following is an example of what I've tried, and it returns an empty dataset.

start_time = '2024-08-21 00:00:00'
end_time = system.date.now()

data=system.tag.queryTagHistory(
	paths=['[exampleProvider]G/G1/Gen Data/Hours'],
	startDate = start_time,
	endDate = end_time
	)

for row in range(data.getRowCount()):
	for col in range(data.getColumnCount()):
		print(data.getValueAt(row, col))

I have also tried using different combinations of the queryTagHistory parameters, and I have tried this with multiple different historized tags. Even if I remove the start and end date parameters so that I'm querying the last 8 hours it still returns the empty dataset when I know there are stored values within that date range.

I know that the function will return a dataset with tag values as None instead of an error if it can't find the specified tag path, so I'm thinking it might not be able to reconcile the tag paths that I am providing for some reason - I just don't know why.

Any ideas?

your startDate is a string, not a date. Use system.date.parse() to convert a string into a date type, or use some other system.date function.

1 Like

I've noted that down now and I'll make sure to do that in the future, though it doesn't seem to have any effect on the function; it still starts with the start_time date despite it being a string, so it must be able to parse the string somehow.

It even mentions in the docs that you can use the string-formatted date:

Or you could use "startDate='2012-05-30 00:00:00', rangeHours=12" to get the first half of the day for May 30th, 2012.

I also mentioned that I'm experiencing the same thing no matter whether I enter startDate and endDate parameters.

Here is the docs link
system.tag.queryTagHistory | Ignition User Manual (inductiveautomation.com)

if you omit the time constraints...

Not sure what to do with this. I have been staring at those docs for a few hours now, and I mention this exact functionality in the original post:

Even if I remove the start and end date parameters so that I'm querying the last 8 hours it still returns the empty dataset when I know there are stored values within that date range.

Check your tag path, and that you do in fact have tag history turned on. Paths is the only required argument, so it has to be one of those two.

paths = ['[default]Millroom/Plant 4/Router 1/Run Status']
history = system.tag.queryTagHistory(paths)
utils.dataset.printDataSet(history)

image

1 Like

I've tried copying the tag path directly from the tag browser, and I have made sure that the tag has history enabled.

Here's a screenshot of the history settings on one of the tags just in case there's something here that might change things:

I selected the history provider from the drop-down list, so I don't think there should be any room for error there.

Try querying your storage provider and see if your tag path in question is listed

SELECT * FROM sqlth_te

I've made sure that the tag shows up in that database, and then I used the matching id column value for that row to verify that the tag has values in the various sqlt_data_1_YYYY_MM tables.

If you are using the right tag provider and still have problems, you need to contact support.

I figured that's where this was heading. Thank you for your help.

1 Like

Hi, did you get a solution for this problem?

I'm experiencing a similar, but different, case.
I'm using same function "system.tag.queryTagHistory" and it´s also returning an empty dataset, with null values.

The case is if I run the same script in "Script Console" it returns the value I want.
More intriguing yet, is that when I press "apply" button in the "Gateway Event Scritps" window, the code is once executed and get the result. But in the time configured for the "Scheduled event" the script brings an empty dataset.

The docs for system.tag.queryTagHistory() says it can be used in Gateway Scope, but it´s not working.