# Dataset is not updating with updateRow?

**URL:** <https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [October 8, 2021, 2:40pm UTC](https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754 "2021-10-08T14:40:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 8, 2021, 2:40pm UTC](https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754/1 "2021-10-08T14:40:36Z")

</div>

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

```auto
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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/5/d5e8820c9d4e5fdd09656c44b0029bf2079934fa.png)

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

```auto
...
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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 8, 2021, 3:50pm UTC](https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754/2 "2021-10-08T15:50:44Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 8, 2021, 4:25pm UTC](https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754/3 "2021-10-08T16:25:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 8, 2021, 4:25pm UTC](https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754/4 "2021-10-08T16:25:51Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 8, 2021, 4:30pm UTC](https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754/5 "2021-10-08T16:30:20Z")

</div>

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 🙃

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 28, 2022, 4:23pm UTC](https://forum.inductiveautomation.com/t/dataset-is-not-updating-with-updaterow/51754/6 "2022-11-28T16:23:07Z")

</div>

A post was split to a new topic: [Issue creating dataset](https://forum.inductiveautomation.com/t/issue-creating-dataset/66984)
