Advice Needed on db Update from Ignition

Ok, it works but it changes every storage type and not just the one that i changed.

def runAction(self, event):
	#assuming that props.data is a dataset
	rowId = self.props.data.getValueAt(event.row, "storage_type")
	#if props.data is in JSON format then it would be
	#rowId = self.props.data[event.row]["ID"]
	
	#update database with edited data.
	query = "UPDATE material_master SET {} = ? WHERE storage_type = ?".format(event.column)
	args = [event.value, rowId]
	system.db.runPrepUpdate(query,args)
	
	#refresh the binding on props.data to pull in the edited data.
	self.refreshBinding('props.data')

Any idea on how to make it only update the cell that was changed?

How do you uniquely identify a row in the DB? What is the Primary Key on that table?

the primary key is sku.

Then you should be using that as your row identifier.

sku = self.props.data.getValueAt(event.row,"sku")
query = "UPDATE material_master SET {} = ? WHERE sku = ?".format(event.column)
args = [event.value, sku]
2 Likes

Morning lrose,

To limit and issues I am doing some "testing" on an inert table.

There is a pic below.

Here is the code, I updated all of the into to reflect this new table.

I am getting this error now:

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:runAction", line 8, in
NameError: name 'self' is not defined

def runAction(self, event):
#assuming that props.data is a dataset
	rowId = self.props.data.getValueAt(event.row, "new_sap_m")
#if props.data is in JSON format then it would be
#rowId = self.props.data[event.row]["ID"]

#update database with edited data.
sku = self.props.data.getValueAt(event.row,"sap_m_number")
query = "UPDATE z_dunnage_tare SET {} = ? WHERE sap_m_number = ?".format(event.column)
args = [event.value, sap_m_number]
system.db.runPrepUpdate(query,args)

#refresh the binding on props.data to pull in the edited data.
self.refreshBinding('props.data')

Your indentation is broken.

Thank you!

Thank you so much for your help!!!

1 Like