what script is needed to save changes to a power tables dataset? I used the default but it doesn’t seem to work.
import system
self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)
what script is needed to save changes to a power tables dataset? I used the default but it doesn’t seem to work.
import system
self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)
Did you remember to make the column editable in the Table Customizer?
yes
Where is it getting its underlying data? Like a query or some other operation?
no I just typed it in the dataset
I see your second line is indented in your post - is it like that in the script? That would be a syntax error.
in my script it is right. But it still doesn’t save the data
Not sure where to go from here. Can you upload an export of the window you’re using?
it stores but if I save it in the designer it overwrites it
Same problem, i dont know what to do to allow the user to edit the table.Taller_electrico_2021-01-25_1319.zip (23.1 KB)
For these tables - do you have a data query going and does that have polling? If so, any edits you do will be lost the next time the data gets polled.
@bkarabinchak.psi, yes, there is a polling query.
@OscarLucas, you will need to update the database table if you want the change to be permanent.
If you have a query polling the database, you dont need to update the dataset, just write to the database and let the query update the table.
You need to add the database name in the update query if not using the default database.
system.db.runPrepUpdate(query, args, “database name”)
Also, you don’t need to import system. that happens automatically.
something like this:
id = self.data.getValueAt(rowIndex, 'id')
query = "Update stock SET %s = ? WHERE id = ?" % (colName)
system.db.runPrepUpdate(query, [newValue, id], "MyDatabase")
system.db.refresh(self, "data")
Check the console, you’re probably getting an error like Column 'id' doesn't exist
because your id column is “idreferencia”, not “id”.
Your column names do not match within your script.
id = self.data.getValueAt(rowIndex, 'idreferencia')
query = 'UPDATE stock SET %s = ? WHERE idreferencia = ?' % (colName)
First of all thank you for the help. I’ve tried again and it still doesn’t work. I have checked project properties, I have tried to change the units from the SQL browser successfully and I cannot find the problem in the script.
Does anyone have any idea what might happen?
Anyone have an example that works?