Restoring a foundset after a delete or omit

I am trying to copy a related foundset from a table view form to restore later, if the user cancels out of a dialog. This table form opens a dialog which allow the user to add new records, edit records and delete records. If the user deletes a record and then cancels from the dialog, I need to restore the deleted records back into the original foundset. My main form, which holds my table view also has enterable fields. I do not want to lose any changes the user made to the main form, but the only way I have found to get my deleted records restored is to rollback the transaction, which also rolls back the main record. Is this possible? I have tried duplicating the foundset and making a copy of the foundset. I have tried to omit the records and load omitted, but nothing I try seems to get me back to the foundset I had before I opened the dialog. Hopefully someone out there can help.

Hi Lenore,

Did you try:

controller.loadRecords(relationName)

When the dialog for opens, I load the records from the table form to the dialog using the following:

globals.lineRecord.sql = databaseManager.getSQL(forms.tech$education_frm.f_personnel_to_f_education.foundset);
globals.lineRecord.sqlParms = databaseManager.getSQLParameters(forms.tech$education_frm.f_personnel_to_f_education.foundset);

forms.education_dlg.controller.loadRecords(forms.tech$education_frm.f_personnel_to_f_education.foundset)

When the dialog is canceled or closed the following executes:

forms.tech$education_frm.f_personnel_to_f_education.loadRecords(globals.lineRecord.sql,globals.lineRecord.sqlParms)

When I used the controller.loadRecords, the foundset on the main form and my dialog become unlinked.

My dialog also has navigation buttons.

I not sure, but I don’t think I can do what I want using this methodology.

I may have to use something like getEditedRecords and loop thru to handle the foundset manually. Or possibly loop thru the foundset and use getChangedRecordData. Either way, I’m beginning to think this is going to be a manual process.

Hi Lenore,

I think the following would work:

  • Show the dialog with the related foundset, set autosave to false
  • Let the user edit and create new records the default way
  • Let the user “delete” records by underwater omitting them from the foundset, keeping track of which records are omitted.

When the user cancels the dialog, you do a rollback of the edited records to revert the new records and record edits and then do a loadAllRecords on the foundset to revert the omitted records.

When the user “ok’s” the dialog, you really delete the records that are omitted from the foundset (using the trackrecord of omitted records that you kept) and then do a saveData to save all unsaved changes.

I think this gives you what you’re after, with just a few lines of code, which can easily be wrapped up in some generic logic that can be reused on any form/dialog/etc.

Paul

Hi Paul,

I tried your suggestion and it would work great if the dialog was only opened once.

The first time I open the dialog, I edit several records.
The second thime, I add a new record.
At this point, everything is working. The table view displays the correct data.

The third time, I delete a record and click cancel.
The rollback edited records, rolls back all the changes made since the first time the dialog was opened.

I need to limit was is reverted to only what changed since the dialog was opened. The previous changes (first and second time) should remain intact.

Lenore

You cannot always save the changes when the user closes the dialog (except when he/she cancels)?

In that case I guess you have to start doing the management yourself. Servoy does not have a concept of rollback point, so you can rollback only part of the unsaved changes.

Paul

I understand and have a new plan.

I am keeping track of the new, edited and deleted records in an object.
I can loop thru my object, which contains the PKs of all changed records.
– getRecordChanges - to restore the original values and delete new records.
— loadAllRecords - to return my omitted records.

I am going to give this a shot. It hope this works.

Thanks Paul

I am happy to report that it is now working.

I am keeping a list of all changed PKs (unique row identifiers) in a global object when anything changes.
Any rows deleted by the user are omitted.

When the user saves, the adds and edits take care of themselves and any omitted records are deleted using deleteRecord.

When the user cancels or closes the dialog, adds are deleted, edited values are restored and omitted records are recovered using loadAllRecords.

Thanks Paul! loadAllrecords was the key to getting the omitted records back.

Lenore