Now I want to go back the other way. I have a named query to which I pass a search term, and it returns a single row containing the following columns and their respective values. When I test the query using the Testing tab of the query builder, it returns something like this:
Now, I want to call this query based on a tag change, and have it load the values into a set of tags which have the same names, within the [default]PrevBatch tag folder, i.e. my tags are:
Answering my own question - eventually got my head around the fact that trying to use the zip function is exactly the opposite of what I need to do here, since I need to separate lists to feed into the system.tag.writeBlocking function.
if currentValue.value and not initialChange:
paths = []
values = []
data = system.db.runNamedQuery('My_ProjectName', 'My_QueryName', {'SearchTerm':'My_SearchTerm'})
for col in range(data.getColumnCount()):
paths.append(data.getColumnName(col))
values.append(data.getValueAt(0,col))
paths = ['[default]Process/PrevBatch/' + path for path in paths]
system.tag.writeBlocking(paths,values)
Always interested in optimisations though, if anyone’s feeling creative!
Since you seem to be familiar with list comprehensions, I’d use a few more, and take advantage of jython’s NetBeans automatic property syntax:
if currentValue.value and not initialChange:
ds = system.db.runNamedQuery('My_ProjectName', 'My_QueryName', {'SearchTerm':'My_SearchTerm'})
paths = ['[default]Process/PrevBatch/' + path for path in ds.columnNames]
values = [ds.getValueAt(0, c) for c in range(ds.columnCount)]
system.tag.writeBlocking(paths,values)