Using Ignition 7.9.9.
I have a situation where I make a copy of an existing ReadData
datatset, iterate through templates that are on screen, and then update a WriteData
dataset. However, it seems like my changes are not taking place at all.
Here is my code - I don’t see anything obviously wrong and I need fresh eyes, if someone can tell my why WriteData is being returned exactly as it was instantiated instead of having the updateRow
affect on it
def makeWriteData(container, ReadData):
"""
Remade for Version 5.0.
Args:
cont: container, the container that is being edited/saved under the window Analysis Test Numbers
ReadData: custom dataset property of the container, uesd to copy and then construct WriteData
Returns:
WriteData: dataset, so that we can leverage app.Table.Save on the Analysis Test Numbers window
"""
from com.inductiveautomation.ignition.common import BasicDataset
import system.dataset
# Version 5: Iterate through components and programtically create a WriteData
# Step 1 - Make copy of ReadData as WriteData
WriteData = BasicDataset(ReadData)
print "in making write data function"
columnsChanged = []
# Step 2 - Iterate through components, looking for ones with a 'Changeable' Property - indicates a template that is allowed
# To be changed and therefore saved in the db
for component in container.components:
# If the component has a Changeable property, then it is a template we want, and if Changeable is True, then we know it was changed and we need to grab it
if component.isPropertyDefined("Changeable") and component.getPropertyValue("Changeable"):
# Then we have a template that is allowed to be changed
componentName = component.getName()
# Minus one becuase the GUI row counting starts at 1, but Datasets start at 0
rowNum = int(componentName.split('_')[-1])-1
# The following line is just a way to drop of the row number of the component name
columnName = str('_'.join(componentName.split('_')[0:-1]))
templateRoot = component.getComponent(0)
templateFlag = templateRoot.getComponent('Flag')
templateLimit = templateRoot.getComponent('Limit')
# Update write data if needed, and set _changed columns = 7
if templateFlag.getPropertyValue("Changed"):
columnName += str('_FLAG')
changedColumn = str(columnName+'_changed')
value = templateFlag.getPropertyValue('WriteValue')
changes = {columnName:value, changedColumn:7, 'userId_changed':7}
print "working on component %s"%(componentName)
print "row number is %i"%(rowNum)
print "ColumnName is %s"%(columnName)
print "Updating row %i with changes %s"%(rowNum, str(changes))
columnsChanged.append(columnName)
columnsChanged.append(changedColumn)
WriteData = system.dataset.updateRow(WriteData, rowNum, changes)
if templateLimit.getPropertyValue("Changed"):
changedColumn = str(columnName+'_changed')
value = templateLimit.getPropertyValue('WriteValue')
changes = {columnName:value, changedColumn:7, 'userId_changed':7}
print "working on component %s"%(componentName)
print "row number is %i"%(rowNum)
print "ColumnName is %s"%(columnName)
print "Updating row %i with changes %s"%(rowNum, str(changes))
columnsChanged.append(columnName)
columnsChanged.append(changedColumn)
WriteData = system.dataset.updateRow(WriteData, rowNum, changes)
print "Changed the following columns: " + str(columnsChanged)
return WriteData
I was debugging this with my console and with the following script and see the following outputs -
Based on my GUI, I would expect that row 0 ATN_01 and row 0 ATN_01_FLAG to be updated to their corresponding GUI values - 1.1 and 2 respectively. My updating row 0 with changes
statements seem to reflect that. But at the very end of my script console script
...
w = app.SQL_Ops.makeWriteData(GHE, ReadData)
print w.getValueAt(0, 'ATN_01')
print w.getValueAt(0, 'ATN_01_FLAG')
When it prints those two values, I get 15.0 and 1, which are the original values before I made the changes on the GUI.
Why is WriteData = system.dataset.updateRow(WriteData, row, changes)
not taking place and affecting my dataset?