Hi,
Does anyone know if databaseManager.refreshRecordFromDatabase() is the best way (fast and not expensive) to refresh a foundset? I tried this function and found that somehow it doesn’t work if there is only one record in the foundset. What I did was:
Open a record list on the main form. The list has just one record in it.
Open another form to edit this record by clicking a button on the main form.
Edit and save the record and then call databaseManager.refreshRecordFromDatabase(mainForm.foundset, -1).
Close the edit form. The record on the main form didn’t get refreshed.
But retry the steps above with 2 records on the main form and it worked!
You say you edit the record from another form. So that would mean you use Servoy objects to edit the record (no rawSQL).
So why do you want to refresh the record ? Servoy should update any form that looks at the same record.
You would use databaseManager.refreshRecordFromDatabase() only when records were edited/added/removed by tools outside of Servoy (like websites).
Thanks for replying.
I need to refresh the list on the main form after the record is edited because the database table of the edit form is different from the table of the main form.
The table of the main form has fields from multiple tables while the table of the edit form is just one of them. So after editing the record the fields showing on the main form need to be refreshed right away.
So, your main form shows data from a record (although related) and in another form you edit that same record’s data and it’s not immediately refreshed on the main form?
Yes. It did refresh the main form but it only happens when there are more than one record on the main form. If there is just one record on the main form then calling databaseManager.refreshRecordFromDatabase(foundset, -1) won’t refresh the main form.
The table of the main form(form name: main_list) is “inventory” which has fields from multiple table;
There is a search function on the main table to search the records in the table “kv_inventory_all”. The search result set might have one or more records;
Click “edit” button to open other form “edit form”. The table of this form is “physical_item”. The reference field between the table “inventory” and “physical_item” is “physical_item_id”;
Edit the record on the edit form;
Save the edited record when clicking “Save” button on the edit form:
var success = databaseManager.saveData();
if(!success)
{
// ok, we've had a failure in the SAVE, find out how many records failed
var records = databaseManager.getFailedRecords();
var fatalerror = "";
fatalerror += "Database error encountered\n";
fatalerror += "Error: " + records[0].exception.getMessage();
forms.graphics_template_dialog.setup_dialog('globals.graphics_fatal_error_handler','Database Error',fatalerror,'Ok');
for(i in records)
{
application.output('record is ' + records[i].exception);
application.output('sql is ' + records[i].exception.getSQL() );
application.output('code is ' + records[i].exception.getErrorCode() );
application.output('setting row created date ');
records[i].row_created_date = new Date();
}
}
else
{
databaseManager.refreshRecordFromDatabase(forms.main_list.foundset, -1);
}
Maybe I’m reading to fast but this code sniplet doesn’t really tell me anything. All I get from it is that you try to do a refresh when the saveData doesn’t fail.
As said before: you shouldn’t have to use the refreshRecord… function if all updates to your data happened from within Servoy.
If you display the same data in different locations in Servoy and edit it in one location, the other locations should automatically refresh, unless:
The data comes from a database view and you edit the underlying table directly, or
The data gets updated outside Servoy directly in the database, or
you update the data from withing Servoy, but you use the rawSQL plugin to do so (This scenario should be avoided!)
If your situation is not one of the above, the refresh should be automatic. If it doesn’t, please create a case with sample solution in our support system
Yes our situation is the #1: the data on the main form comes from a view and the data on the edit form comes from the table. Currently what we did is:
find out the index of the edited record on the main form;
call databaseManager.refreshRecordFromDatabase(mainForm.foundset, index).
We tried to call databaseManager.refreshRecordFromDatabase(mainForm.foundset, -1) but it didn’t refresh the data on the main form if there is just one record on the main form.
We are using servoy 4.1.5 and we have no plan to upgrade it to 5.1 so we’ll open a ticket for the issue: databaseManager.refreshRecordFromDatabase(foundset, -1) doesn’t refresh the list which has just one record.
I have another question: why plugins.rawSQL.flushAllClientsCache(server, table) doesn’t work either? Here the table name assigned to plugins.rawSQL.flushAllClientsCache() is the view of the main form but it doesn’t refresh the list on the main form. Should anything else be called before calling plugins.rawSQL.flushAllClientsCache() or under some situations this plugin doesn’t work?