Table ID property

I am trying to use the 7.9 database manipulation delete button in 7.7.8 but I get a “AttributeError: ‘NoneType’ object has no attribute ‘id’” I went into help to see if that was a property in 7.7.8 but could not find it. I search 7.9 and could not find it there either. Is there something special that needs to be done to access this property?

id = event.source.parent.getComponent('Inventory').id

if system.gui.confirm("Are you sure you want to delete the selected inventory item?"):
	system.db.runPrepUpdate("DELETE FROM inventory WHERE id = ?", [id])
	system.db.refresh(event.source.parent.getComponent('Inventory'), "data")
	system.gui.messageBox("Inventory item deleted")

What type of component is “Inventory”? If it’s a text box or number box the attribute might be .text or .int or something like that. id wouldn’t be a property unless you put a custom property on it.

Inventory is a table. Thank you about the custom property comment. I believe that is it. I will go and look for that.

Ok, if you want to get the id of a selected row in the table then you’ll have to create a custom property on the table called “id” and bind it to an expression like this:

if({Root Container.Inventory.selectedRow} != -1, {Root Container.Inventory.data}[{Root Container.Inventory.selectedRow}, 0], 0)

Where the 0 in [{Root Container.Inventory.selectedRow}, 0] is the column index of your ID field in the table.

You can also do this with a try statement:

try({Root Container.Inventory.data}[{Root Container.Inventory.selectedRow}, 0],
-1)

Also be careful to use -1 and not 0 as the fallback value; you wouldn’t want it to be mistaken for a real id!

DataTable = event.source.parent.getComponent('Inventory')

id = DataTable.data.getValueAt(DataTable.selectedRow,"id")

if system.gui.confirm("Are you sure you want to delete the selected inventory item?"):
   system.db.runPrepUpdate("DELETE FROM inventory WHERE id = ?", [id],"NameOfDBConnection")
   system.db.refresh(DataTable, "data")
   system.gui.messageBox("Inventory item deleted")

Thank you everyone! Your comments worked.