With system.tag.queryTagHistory() how can we force this API to use specific historian db to retrieve data?
Sometimes for testing people assign tags to one DB and after a while, they change them to another DB. So the tag history data will be on both DBs.
Even when I set the default DB in the tag provider, this API can't retrieve data and try to get the data from the first DB.
The API accepts paths with tag provider names but no cue for historian DB. I believe it should use the default set db in the tag provider setting but it seems it doesn't care about it.
There are tag paths and history paths. If you give the historian a simple tag path, it will look up the tag's storage provider and convert to a local history path. If you want anything else, you need to provide a history path instead of a simple tag path.
See this topic:
Ok I know that but where we define the default tag's storage provider? If in tag provider config page, it doesn't work for me. That's my problem
When you set up a Database as a Historical Provider it becomes available to the designer, as a selection in the history section of the tag editor (as you know).
If you want to look up history for a tag path on a different provider than what is set in the tag editor, then you will need to manually construct the Historical tag path with the correct Historical Provider.
Here is a little script I adapted that shows how to do it (aside from manual concatenation).
def getHistoricalTagPath(path):
from com.inductiveautomation.ignition.common import QualifiedPath, WellKnownPathTypes,QualifiedPathUtils
from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser
qPath = QualifiedPathUtils.fromTagPathNew(TagPathParser.parseSafe('default',path))
gateway = system.tag.readBlocking('[System]Gateway/SystemName'])
driver = ':'.join([gateway.value,qPath.getPathComponent('prov')])
return QualifiedPath.Builder().set(WellKnownPathTypes.HistoryProvider,'YourHistoryProvider').setDriver(driver).setTag(qPath.getPathComponent('tag')).build().toString()
You can find the original script and conversation here: