system.tag.browseHistoricalTags will not return the tag path for Historical Tags

Im experiencing an issue with the system.tag.browseHistoricalTags() function when called via a property change script. I also attempted via a button. I know the tags are available in MySQL DB because I can query them using the system.tag.queryTagHistory() function. For the Sake of testing I set up a new folder with 3 different tags which all log some Tag History. I understand why I get the NoneType error (because I am trying to pull the path of a null value), however, I dont understand why it is returning a null value.

QUESTION:
Why is system.tag.browseHistoricalTags() returning no information when there are clearly tags with history in this subfolder? Am I doing something wrong? Am I misunderstanding the use of this function?

image

Here is the output of my print statements:

BrowseResults [results=null, totalAvailableResults=0, continuationPoint=null, resultQuality=[GOOD]]
None

This is the Code I am running:

		#	This script will browse for any history tags at the specified historical path and print out all of their Historical Tag Paths to the console.
		path='histprov:Hist_DB:/drv:Basic_Gateway:MY_TAG_PROVIDER:/tag:TEST_HISTBROWSE'
		#	We call the function and place the BrowseResults that get returned into a variable called browse.
		browse = system.tag.browseHistoricalTags(path)
		#	We can then call getResults() on the BrowseResults variable, and store that in a variable called results.
		print browse
		results = browse.getResults()
		#	We can now loop through the results in a for loop.
		print results
		for result in results:
		#	We then call .getPath() on the individual objects to get the Tag Path.
			print result.getPath()

I get the following error:

Traceback (most recent call last):
  File "<event:propertyChange>", line 13, in <module>
TypeError: 'NoneType' object is not iterable

	at org.python.core.Py.TypeError(Py.java:235)
	at org.python.core.PyObject.__iter__(PyObject.java:798)
	at org.python.pycode._pyx138.f$0(<event:propertyChange>:13)
	at org.python.pycode._pyx138.call_function(<event:propertyChange>)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1275)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:636)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:193)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.access$000(ActionAdapter.java:41)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter$ActionRunner.run(ActionAdapter.java:299)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.9.14 (b2020042813)
Java: Oracle Corporation 1.8.0_251

That usually indicates results is coming back empty.
Put an if around it checking the len of results.

if len(results)>0:
    for result in results:
else:
    print 'No Tags Found'

Then reference the page for how to actually build your path.
https://docs.inductiveautomation.com/display/DOC79/Export+Tag+Historian+to+CSV#ExportTagHistoriantoCSV-HistoryTagSearchandExport

Thank you, I will be sure to do that for Error Handling.

However, I’m more concerned about why tag paths did not come back when specifying the folder that contains tags with tag history enabled? I figured this function would have returned something like:

[“TEST_HISTBROWSE/TEST_Hist1” , “TEST_HISTBROWSE/TEST_Hist2” , “TEST_HISTBROWSE/TEST_Hist3”]

so that I could itterate through this list when using the function system.tag.queryTagHistory(). Is this how the browse function is supposed to work? Im confused as to what this function is supposed to return.

Basically I am trying to assign the top level of a folder (that has nested folders), and find all of the tag paths that are logging to the tag historian. Otherwise I would need to write out all of the tag paths for each individual tag which is very time consuming.

Any help would be appreciated!!

Are you sure that part of your path is correct?
I copied your code, adjusted the paths and it worked fine.

The path is correct because I was able to pull the actual results using the queryHistoricalTags() function:

	#	This script will browse for any history tags at the specified historical path and print out all of their Historical Tag Paths to the console.
	path='histprov:Hist_DB:/drv:Basic_Gateway:MY_TAG_PROVIDER:/tag:TEST_HISTBROWSE'
	#		We call the function and place the BrowseResults that get returned into a variable called browse.
		browse = system.tag.browseHistoricalTags(path)
	#		We can then call getResults() on the BrowseResults variable, and store that in a variable called results.
		print browse
		results = browse.getResults()
	#		We can now loop through the results in a for loop.
		print results
		#	Results is an object, use "is not None"... If results were a string, use "len(string) != 0"
		if results is not None:
			for result in results:
			#	we then call .getPath() on the individual objects to get the Tag Path.
				print result.getPath()
		else:
			print 'No Tags Found'

#	 Try the .queryTagHistory function
		endTime = system.date.now()
		startTime = system.date.addMinutes(endTime, -30)
		print endTime
		print startTime
		TagPaths=[]
		TagPaths.append("[MY_TAG_PROVIDER]TEST_HISTBROWSE/TEST_Hist1")
		data = system.tag.queryTagHistory(paths=TagPaths, startDate=startTime, endDate=endTime, returnSize=0, returnFormat='Wide')
		print data

I get the following in my Output Console:

BrowseResults [results=null, totalAvailableResults=0, continuationPoint=null, resultQuality=[GOOD]]
None
No Tags Found
Tue Aug 18 16:53:50 PDT 2020
Tue Aug 18 16:23:50 PDT 2020
Dataset [180R ? 2C]

Is there any troubleshooting suggestions I might go through? Can you give me an example of what printed to your output console when you ran the browse function? Thanks for the help!

Create a temporary window, drag a Tag Browse Tree onto it.
Set it to Historical Tag mode.
Put designer in Run mode, drill down through the tree to the historical tag you are testing.
Select it.
Then on the controls properties open the Selected Paths dataset and look at the tags FULL path.
That will show you the provider, server, tag path, that you need to be using.

Thank you. That was informative, however its still not working and only shows Null. Im going to shelve this for a while. If I figure out the issue I will post here later.

If you post screen shots of the expanded tree and the dataset of the selected tags property we can further verify your paths.

I have run into issues where I’ve had to restart the tag history module in order to get newly-logging tags to show up, particularly for remote tag providers. Assuming you haven’t already found a fix, Perhaps try this. If it works, I’ll mention you in the open ticket I have for this issue…