Page 1 of 1

Cancel new record transaction -> deletes existing record

PostPosted: Wed Apr 11, 2012 11:38 am
by djlapin
When the user presses a (+) button next to a table-view list of users (a tab panel list), I add the new record to the table view, and then display the new record in a data entry form,

Code: Select all
function onClick_addUser(event) {
   forms.user_info_incl.foundset.newRecord(false);
   forms.user_info_incl.usr_tenant_id = selpa_select_id;
   globals.newRecordFormName = 'user_info_i'
   var editUserWin = application.createWindow('editUserWin',JSWindow.MODAL_DIALOG);
   editUserWin.title = "Add new program user..."
   editUserWin.show(forms.user_info_i);
}


For a new record, the data entry form (user_info_i) acquires a lock and begins a transaction in the onShow.

If the user *cancels* the new record, I am doing this onAction,

Code: Select all
function onClick_bCancel(event) {   
   var editUserWin = application.getWindow('editUserWin');   
   if(databaseManager.hasTransaction()) {   
      databaseManager.rollbackTransaction();
      var lockName = 'user_info_' + usr_user_info_id;
      databaseManager.releaseAllLocks(lockName);      
   }
   if (globals.newRecordFormName == 'user_info_i')  {  // it is a newly-created record
      forms.user_info_i.controller.deleteRecord();      
   }
   editUserWin.destroy();
}


When the program returns to the form showing the tab panel list, there is one less *existing* record in the list. As long as I don't include the controller.deleteRecord() in the cancel, I'm okay.

In other areas of the program, the same code (with the deleteRecord()) works as I would expect it to -- the new record (created outside the transaction) is deleted in the table view.

The table view and the data entry form share the foundset.

What is different about this case?

Thank you,
Don

Re: Cancel new record transaction -> deletes existing record

PostPosted: Tue May 01, 2012 9:43 am
by jcompagner
the difference is in:

databaseManager.rollbackTransaction();

that will also by default rollback the edited records, please check the boolean argument

Re: Cancel new record transaction -> deletes existing record

PostPosted: Thu May 03, 2012 5:31 pm
by djlapin
Hi Johan,

Which Boolean argument are you referring to?

But the new record is created in the list, outside of the transaction. The transaction is started in the onShow of the dialog. So the rollbackTransaction should not delete the record itself, right?

Thank you for responding,
Don

Re: Cancel new record transaction -> deletes existing record

PostPosted: Thu May 03, 2012 10:21 pm
by jcompagner
since 6.0:

http://wiki.servoy.com/display/public/D ... ransaction

if you do rollbackTransaction then by default we also rollback all edited records.