Hi,
this method I’ve made in Ignition 8.0 perspective.
I’m trying to find a specific value “id” in a column. For each row that has a matching value in the specified column “Col 1” I want to make a new dataset of these rows.
This is the structure of the data when I write it to a label:
The structure of the header when I write it to a label:
I’m getting an error message of:
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File “”, line 5, in runAction File “”, line 19, in findNotes IndexError: Row 0 doesn’t have the same number of columns as header list.
I can’t see that they should be of different sizes… Any help?
def findNotes(self, id):
"""
Custom method that can be invoked directly on this component.
Arguments:
self: Reference to this component
id: Value to find in column of table
"""
tbl = self.getSibling('Table').props.data
newData = []
col = "Col 1"
colNames = list(tbl.getColumnNames())
for row in system.dataset.toPyDataSet(tbl):
rowList = []
value = row[col]
if value == id:
rowList.append(list(row))
newData.append(rowList)
ds = system.dataset.toDataSet(colNames,newData)
return ds
I can’t be positive - because I don’t know how the bindings were applied to the Labels in the screenshots you posted - but I see that the first screenshot has length of 1, while the second has length 11. In the first screenshot, you have 11 values inside a list of length 1, which is in another list of length 1 - so any length comparisons would return the length of the outer-most object, which is a list of length 1.
This looks to be the cuplrit.
row
is a list
- then you benignly wrap it in a list (end result is no change)
- then you append this list to a list. (
rowList
)
- then you append that list of a list to another list (
newData
)
Yes, correctly I had appended this once too much.
I found one more mistake, I declare the rowList = []
inside the for loop, nesting it further. So once I moved this outside the loop, it works!
Thank you.
Just for clarity for other users, could you post the corrected code?
def findNotes(self, id):
"""
Custom method that can be invoked directly on this component.
Arguments:
self: Reference to this component
id:
"""
tbl = self.getSibling('Table').props.notesData
col = "Col 1"
colNames = list(tbl.getColumnNames())
rowList = []
for row in system.dataset.toPyDataSet(tbl):
value = row[col]
if value == id:
rowList.append(list(row))
ds = system.dataset.toDataSet(colNames,rowList)
return ds