Delete records from a table

Just to be clear, you’re talking about the “Group Email Table” component on the “User Email” popup, right? I simplified the Delete Email script, since all you need to know to delete an item in the database is its primary key id (assuming it’s unique, which based off of your database screenshot and your scripting, it should be). You also don’t need to have a hidden component querying a PK value for the drop down value. Here is what I did:

[ul]- changed the polling mode of the query for the “data” property binding of the “Group Email Table” to off (your script should have system.db.refresh in the add/delete scripts, so it only refreshes the table when necessary)

  • changed the query for that same “data” property to the following so it brings back the primary key with its associated data: select emailkey, email
  • opened the table customizer for “Group Email Table” and hid the emailkey column
  • changed the script to reference the selectedValue (notSelectedStringValue) of dropdown list, which is the primary key of data to be deleted[/ul]

Here is the new script for Delete Email, a lot simpler and just requires that primary key value from the dropdown list. Let me know if the data in the table still doesn’t refresh properly for you.

table = event.source.parent.getComponent("Group Email Table")
EmailKeyValue = event.source.parent.getComponent('Delete Email Dropdown').selectedValue

system.db.runUpdateQuery("DELETE FROM emails WHERE EmailKey = %d" % EmailKeyValue)

event.source.parent.getComponent('Delete Email Dropdown').selectedValue = -1
system.db.refresh(table, "data")

overviewWindow = system.gui.getWindow('Overview').getRootContainer()

if EmailRole == "User":
	system.db.refresh(overviewWindow.getComponent('CustomerEmailTable'), "data")
elif EmailRole == "Dist":
	system.db.refresh(overviewWindow.getComponent('DistEmailTable'), "data")
elif EmailRole == "Nass":
	system.db.refresh(overviewWindow.getComponent('NassEmailTable'), "data")