Dataset is not updating with updateRow?

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 -
image

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?

updateRow could silently not do anything if the column names don’t exactly match… what if you (for a test) tried referring to the columns by index, instead of name? Maybe there’s a discrepancy between the column names.

Consider using DatasetBuilder to construct your WriteData row by row while reading from ReadData. It will be notably faster, too.

1 Like

Turns out the error … was me. You were right about column names being wrong - my second if statement’s columns were incorrect in the event both the flag and limit of a template were changed. The culprit

if templateFlag.getPropertyValue("Changed"):
	columnName += str('_FLAG')  //This line right here was messing pu
	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} //the column name here

If flag changed, then my columnName became ATN_01_FLAG, and that would carry over to my second if statement, but it should not hvae. This explains why te writes and sql queries all looked wrong.

Correcting this has fixed the issue. Thanks for taking a look.

Good to know for the future. Unfortunately with this particular window, going through the templates on on different containers in the same window, it seems like the order I get them in is not in the same order as my dataset rows, so though I could probably do this, the whole dataset is only 8 rows so theres no real noticeable slowdown now that its working. More importantly client deadlines loom :upside_down_face:

A post was split to a new topic: Issue creating dataset