No errors, onCellEdited script not working

I have a power table that runs a script onCellEdited. It updates the db and refreshes the data in the table to reflect the change. Next it sends an email out to notify someone of the change, then finally it logs the change in a db table. I have code on another table that is identical to this, except it edits a different db table and it works perfectly. This table however will not send the email or log the change in the db. I’ve looked over it for 2 hours and cannot figure out why it fails. The weird thing is there is no error messages that pops up, it just quits at the email portion. I know for a fact that it stops at the email portion and not before. I will have a java error message box that will show up minimized every so often, but when I try view the error nothing shows up???

	import system
	import datetime
	if self.parent.getComponent('EditButton').selected == 1:
		self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)
			
		if newValue == oldValue:
		   return
		else:
			ndx = self.data.getValueAt(rowIndex,0)
			system.db.runPrepUpdate("UPDATE mill_programcodes SET %s=? WHERE mill_programcodes_ndx=?"% colName, [newValue,ndx])
			system.db.refresh(self,"data")
			
			style = self.data.getValueAt(rowIndex, 'style')
			system.gui.messageBox('It got this far')
			smtp = "xxx.xxx.com"
			sender = "xxx@xxx.com"
			subject = "Millroom Program Edit"
			body = "<HTML>There has been an edit to Millroom Program Database.<br/> Style Edited: "+ style + "<br/>Column Edited: "+colName+"<br/> New Value:" + newValue + "<br/> Old Value:" + oldValue + "</HTML>" 
			recipients = [ xxxxx emails]
			system.net.sendEmail(smtp, sender, subject, body, 1, recipients) 
			
				
			action = "Change At: "+ colName + ' Old: ' + oldValue + ' New: ' +newValue  
			user = system.tag.read("[System]Client/User/Username").value
			time = datetime.datetime.now()
			system.db.runNamedQuery('Styles/LogChange', {'action':action, 'user':user, 'time':time, 'style':style})
			
		
	else: system.gui.warningBox('<font size = 20>Not in edit mode</font>')

Well I found out that it works up to the point where I have newValue and oldValue. If I take out the reference to newValue and oldValue it works. This code is exactly like another table I have and It works on that one??

Are you getting any error messages on your console? I’m wondering if you have an indentation problem with the code you copy/pasted from one table to the other.

The code you pasted must not start at the far left column of the window. It needs to be indented one tab to have access to the newValue and oldValue variables that the code at the top of the window is providing.

You should have been seeing a console error message regarding those variables if this were the case though, so I’m not sure this is your problem.

1 Like

Yes it is indented one tab over, and no errors when I try to execute the script. It does work if I take the newValue and oldValue variables out. I’ll update if I find anything else out, until then I will continue my head scratching. thanks

Amazing what a few hours off from work and some sleep will do for a problem you can't solve. It just occurred to me that the query I am running uses the newValue variable with success but not in the email message. Then it hit me, the '+' for python concatenation only works on strings, and the variable I was changing is of type int. I put str() around the variables and it worked perfect. :joy:

1 Like