Hello,
I am trying to perform delete operation in a table using database and script.
I am trying to call a named query through scripting, but there's an error saying Transaction databaseName is closed
If I try to include the args as list, I will get another error saying Cannot coerce value '[{'sensor_id': 12}]' into type: interface java.util.Map
if selectedRow >= 0:
data = (table.data).getValueAt(selectedRow, 'sensor_id')
# Ask for confirmation
confirmed = system.gui.confirm("Are you sure you want to delete the selected row?")
if confirmed:
args = {'sensor_id': data} # Using a dictionary for named parameters
event.source.parent.getComponent('Label').text = str(selectedRow) + str(data)
# Delete from database using the named query
query = "displayDeleteUser"
result = system.db.runNamedQuery("displayDeleteUser", args, "databaseName")
system.db.refresh(event.source.parent.getComponent('Table'), "data")
else:
print("Deletion cancelled.")
else:
system.gui.errorBox("Please Select a Row to Delete", "Selection Error")
The function's third argument is either tx or parameters, depending on the scope.
From the error you're getting, it is clear that you're calling the function in the client/session scope, and that it expects the third argument to be a transaction id.
Remove the third argument and you'll be fine.
PS: the database used by named queries are defined by the named query itself, not by the function that calls it.
PPS: Try to find a better title next time. This one says absolutely nothing about the issue you have: 2 out of the 3 words are already in the tags, and the last one, well... you probably wouldn't be posting if everything was fine.