Using queryTagHistory to retrieve data that had been stored using storeTagHistory

Hi everyone,

I’ve run into problems with retrieving history data from a tag using system.tag.queryTagHistory

Here is my situation:

I need to make history of a value of a tag but it needs to be one shot based on condition so I created a value changed scripting on a tag that goes along the lines of:

if (currentValue.value > slow_cycle and previousValue.value < slow_cycle) or (currentValue.value > watchdog and previousValue.value < watchdog):
	historyprovider = 'TagHistoryDB' 
	tagprovider = 'JR219'
	paths = ['[JR219]New Instance/A']
	values = [currentValue.value]
	
	system.tag.storeTagHistory(historyprovider, tagprovider, paths, values)
	logger = system.util.getLogger(tagPath)
	logger.info('history inserted')

and when I check the TagHistoryDB, I can see that the tagpath exists in the sqlth_te. Buth when I try to retrieve the data using system.tag.queryTagHistory(['[JR219]New Instance/A']), it returns 0 rows. I tried the tag history on binding but same thing happened. I can retrieve the history of a tag that has it’s History Enabled set to true.

It would be immensely appreciated if anyone could share their thoughts on this and many thanks in advance!

Ignition's historian cannot do condition-based storage. If a tag is not configured for normal history storage, it won't have the necessary metadata for retrieval, either.

Use a transaction group (SQL Bridge module) or a custom event script to store your values and query bindings to retrieve them.

1 Like

hi pturmel, thank you for your response.

I will have a look into the transaction group, I’m new to the Ignition platform and still in a discovery phase but it’s good to know that Ignition has a lot of cases covered out of the box.

Storing tag history in one shot was doable with scripting using storeTagHistory and I was able to retrieve the data using queryTagHistory by pointing it at the History Provider rather than the tag in the Real Time provider.

Not sure what magic goes on behind the scene when the history is stored using the History Enable option on the tag itself, but I couldn’t retrieve the tag history if the history was stored using storeTagHistory unless I refer to the tags in the History Provider.

1 Like