Table with tags and their values

I am creating a table where it displays the tags and their values. I used a timer to refresh the contents of the table. I cant figure out how to append the values of the two scripting functions which are the system.tag.browseTags and system.tag.readAll in a single dataset
Thanks for the help

if event.source.value >= 1:
	path = []
	tagDataset = []
	blank = []
	tagHeaders = ['name', 'fullPath', 'type', 'dataType', 'value', 'quality']
	values = system.tag.readAll(path)
	browseTagArray = system.tag.browseTags(parentPath="folder/folder/test")
	
	for tag in system.tag.browseTags(parentPath="folder/folder/test"):
		path.append(tag.fullPath)
	
	for browseTag in browseTagArray and QualifiedValue in values:		
		tagDataset.append([browseTag.name, browseTag.fullPath, browseTag.type, browseTag.dataType, QualifiedValue.value, QualifiedValue.quality]);

	data = system.dataset.toDataSet(tagHeaders, tagDataset)
	table = event.source.parent.getComponent("Table")
	table.data = data

You have a couple mistakes and a missed opportunity:

  • First, your call to system.tag.readAll() is occurring before you’ve constructed the list of paths. Move it to after your first for loop.
  • Second, your 2nd for loop is not valid python/jython syntax. A for loop can only iterate over one list. You must combine your two lists into a list of pairs. The built-in zip() function will do this. Like so:
for browseTag, QualifiedValue in zip(browseTagArray, values):
    tagDataset.append(....)
  • Finally, you are calling system.tag.browseTags() twice. Just use your browseTagArray in your first for loop.

Thanks you so much! it works. I notice that the QualifiedValue.value only accept integer values. Is there a way to read the double and float values?

Not true. Each will have the datatype of the underlying tag. If that’s not what you’re seeing, you’re doing something wrong.

I tried to put a float and double datatype tag in the parentpath. And it gives an error of “Unable to convert row 3, column 5 to type class java.lang.Integer”. But if the tag is an integer and boolean dataType only there’s no error.

Ah, your problem is in the system.dataset.toDataSet() utility. Datasets must have a single datatype for a column, and that function uses the first row to establish the types. You’ll need to go under the hood and use the DatasetBuilder, where you can explicitly specify your types. You’ll need java.lang.Object for your variant column.