# Table .cellEdited - Revert to original value?

**URL:** <https://forum.inductiveautomation.com/t/table-celledited-revert-to-original-value/8878>\
**Category:** Ignition\
**Created:** [August 7, 2014, 8:52pm UTC](https://forum.inductiveautomation.com/t/table-celledited-revert-to-original-value/8878 "2014-08-07T20:52:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paullys50](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paullys50/32/3324_2.png) [@Paullys50](https://forum.inductiveautomation.com/u/Paullys50)\
**Post date:** [August 7, 2014, 8:52pm UTC](https://forum.inductiveautomation.com/t/table-celledited-revert-to-original-value/8878/1 "2014-08-07T20:52:40Z")

</div>

I have a column in a table called “value”, this can be edited. The edit is done via-scripting on the .cellEdited event handler. All works well.

Now I have added min/max checks to ensure the new value does not exceed these limits. The checks work as expected.

However, if the check fails, the “new” entered value is displayed on the table, as if it wrote to the table, but it really didn’t.

Example:

Current value = 60  
Min = 0  
Max = 100

New value = 101

Result: Error message appears indicating value exceeds limits.

Cell value = 101 (but it didn’t really write 101 back to my database)

Here is the section of code in question:

```auto
if columnName =="Value":
	primaryKeyValue = event.source.data.getValueAt(event.row, "No.")
	minValue = event.source.data.getValueAt(event.row,"Min")
	maxValue = event.source.data.getValueAt(event.row,"Max")
	
	#Check limits
	message = "New Value: %s Exceeds Limits, please enter a value between %s and %s" %(event.newValue,minValue,maxValue)
	if float(event.newValue) >= minValue:
		if float(event.newValue) <= maxValue:
			# Check if this is an integer value change or real value change
			# Selection parameters are integer values, IsSelection = True indicates integer value
			if event.source.IsSelection == 0: 
				query = "UPDATE viwRecipeEditor SET fltParamValue =? WHERE intPLC=? AND intProg=? AND intParamNumber=?"
			else:
				query = "UPDATE viwRecipeEditor SET intParamValue =? WHERE intPLC=? AND intProg=? AND intParamNumber=?"
				
			system.db.runPrepUpdate(query, [event.newValue,event.source.data.getValueAt(event.row, "PLC") , event.source.data.getValueAt(event.row, "Prog"), primaryKeyValue],'GEADB')
		else:
			system.gui.errorBox(message)
	else:
		system.gui.errorBox(message)
```

Seems like the table is showing the .newValue attribute on the table. What is the best way to “reset” this? Upon the error I tried to do event.newValue = event.oldValue but that failed because it is a ‘read-only’ attribute’.

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [August 7, 2014, 9:06pm UTC](https://forum.inductiveautomation.com/t/table-celledited-revert-to-original-value/8878/2 "2014-08-07T21:06:20Z")

</div>

You could try something like this:

```auto
if not iSuccess:
	event.source.data = system.dataset.setValue(event.source.data, iRow, iCol, event.oldValue)
```

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [August 7, 2014, 9:21pm UTC](https://forum.inductiveautomation.com/t/table-celledited-revert-to-original-value/8878/3 "2014-08-07T21:21:00Z")

</div>

Using your code:

```auto
if float(event.newValue) >= minValue and float(event.newValue) <= maxValue:
         # Check if this is an integer value change or real value change
         # Selection parameters are integer values, IsSelection = True indicates integer value
         if event.source.IsSelection == 0: 
            query = "UPDATE viwRecipeEditor SET fltParamValue =? WHERE intPLC=? AND intProg=? AND intParamNumber=?"
         else:
            query = "UPDATE viwRecipeEditor SET intParamValue =? WHERE intPLC=? AND intProg=? AND intParamNumber=?"
            
         system.db.runPrepUpdate(query, [event.newValue,event.source.data.getValueAt(event.row, "PLC") , event.source.data.getValueAt(event.row, "Prog"), primaryKeyValue],'GEADB')
else:
      system.gui.errorBox(message)
      event.source.data = system.dataset.setValue(event.source.data, event.row, event.column, event.oldValue)
```

---

<div class="post-metadata">

**Author:** ![Paullys50](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paullys50/32/3324_2.png) [@Paullys50](https://forum.inductiveautomation.com/u/Paullys50)\
**Post date:** [August 7, 2014, 9:44pm UTC](https://forum.inductiveautomation.com/t/table-celledited-revert-to-original-value/8878/4 "2014-08-07T21:44:27Z")

</div>

Thanks for the help!

As soon as I saw your code it clicked, I wasn’t correlating data properly…not enough caffeine today!
