Problem with system.tag.queryTagHistory

I am having a problem with a tag history query.

I have a system that stores the history of numerous tags. The historical scan class is set to 10s and it will only write on change. This was done to minimize the communication because Ignition is running in the field and sending to a cloud db over a cellular connection.

I am using the historian to create on the fly batch reports. I run several queries for a particular time period and then move that data into various charts.

Most of the data being stored is from discrete tags. For the most part the query works great. I found that setting the returnSize=0 and aggregationMode=“LastValue” seem to give me good data. However, I have one tag where the data returned is incorrect.

If I look into the actual databases, I can see that the tag comes on at 12:03:40. However, my resulting queryTagHistory shows the tag coming on at 12:01:10. If I switch the returnSize to -1, then the query shows that the tag turned on at 12:03:40.

Unfortunately, I don’t seem to be able to run this query using the returnSize=0. This is because the top rows of the resulting dataset are null. I believe this is because the data was only writing to the db upon change. The queryTagHistory seems to leave the starting values for the tags at Null until it sees a value change.

Is there a way I should be setting the parameters in the queryTagHistory that will get me a dataset with no null values and correct values?

I want to bump this back up.

Has anyone seen a similar problem with the tag historian? If I can’t get an answer here, I’ll have to call in to tech support Monday to see why the tag historian would give me the wrong time for a tag change.

Well, I didn’t get an answer from anyone on this issue. However, I did figure out the solution and thought it might be useful for someone else.

When querying the tag history using system.tag.queryHistory

  • If you are querying a tag that has a historical scan class of “Evaluate on Change” or is set to “Unlimited” time between historical writes
    • If the Return Size is set to “0”, then you could get blank data at the beginning of the returned dataset. The data will remain blank until a change in the tag value occurs
    • If instead the Return Size is set to a positive number, the returned dataset will return with every row filled in.