I think that’s the heart of the matter, and the answer.
If the only object that supports nesting is QueryResults then that’s probably the only way to do it. It just feels odd creating something called QueryResults from data that isn’t really the result of a query.
I just want to make sure that there isn’t some other way I’m overlooking.
Sounds like we are going down the only possible path for what we want to do. I’m just struggling a bit getting it to work right.
Here is what I have, and I’m clearly doing something wrong. It works f I comment out the second lineData.append, but crashes the report if I use both
from system.report import QueryResults
logger = system.util.getLogger("cLogger")
headers = ["Area", "LinePath", "Line", "EquipmentName", "OEE", "OEE Availability", "OEE Quality", "OEE Performance"]
lineData = []
lineData.append(["1", "2", "3", "4", "5", "6", "7", "8"])
lineData.append(["x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8"])
primaryDS = system.dataset.toDataSet(headers, lineData)
parentqr = QueryResults(primaryDS)
count = 0
for theRow in lineData:
eqPath = theRow[1]
logger.info("start row process path %s" % eqPath)
headers2 = ["Duration", "Reason"]
subData = []
childList = []
for reasonCount in range(3):
subData.append(["Dur %s" % reasonCount, "Reas %s" % reasonCount])
tempDS = system.dataset.toDataSet(headers2, subData);
logger.info("ok %s" % tempDS)
childList.append(QueryResults(tempDS, parentqr, count))
logger.info("added subdata %s" % count)
count += 1
parentqr.addNestedQueryResults('DowntimeReasons',childList)
data['OEEDT'] = parentqr
Exception thrown in designer console is:
11:06:50.754 [AWT-EventQueue-0] WARN reporting.Preview - Error generating preview
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at com.inductiveautomation.reporting.designer.workspace.design.PreviewPanel$PreviewDataXmlWriter.writeQueryResults(PreviewPanel.java:342)
at com.inductiveautomation.reporting.designer.workspace.design.PreviewPanel$PreviewDataXmlWriter.writeObject(PreviewPanel.java:385)
at com.inductiveautomation.reporting.designer.workspace.design.PreviewPanel$PreviewDataXmlWriter.writeMap(PreviewPanel.java:312)
at com.inductiveautomation.reporting.designer.workspace.design.PreviewPanel$PreviewDataXmlWriter.toXml(PreviewPanel.java:294)
at com.inductiveautomation.reporting.designer.workspace.design.PreviewPanel$PreviewDataXmlWriter.toXml(PreviewPanel.java:271)
at com.inductiveautomation.reporting.designer.workspace.design.PreviewPanel$PreviewGenerator.done(PreviewPanel.java:111)
at java.desktop/javax.swing.SwingWorker$5.run(Unknown Source)