databaseManager.rollbackEditedRecords();

I have created a form with a table view and have the onLoad to set AutoSave(false). The form has buttons to save, add, cancel…

When I add a record with

currentcontroller.newRecord(true)

Then if I cancel adding that new record

databaseManager.rollbackEditedRecords();

and save with

databaseManager.saveData();
var array = databaseManager.getFailedRecords();
for( var i = 0 ; i < array.length ; i++ )
{
//do error stuff here
}

The record that was added without data still causes the routine to fail.(Which makes sense because it was added and not edited) Is there a way to delete added records along with the edited records out of the failed records?

Thanks for any and all help.

I haven’t changed my transaction based logic yet, but my feeling tells me a new record should be considered as edited. So rollbackEditedRecords() should also rollback newly created records. This is a point where maybe somebody from the dev team could shed some light on. I think this is a very important question and as soon as I switch to Servoy “transactions”, I will ask the same question.

I would say in the logic of RDBMS’s a rollback undoes any edited records, deleted records and added records.
Servoy (internal) transactions should act the same.

databaseManager.rollbackEditedRecords() works fine for me and deletes the record that has been created but not saved, are you sure you don’t do something else in your onShow or onLoad method? Maybe you are using DB managed PKs?
The real problem is that deleted records are not “undeleted” when you use databaseManager.rollbackEditedRecords(): if you have a portal and delete a row the rollback won’t add the related row back for you.
To overcome this I start a DB transaction before deleting related records and check if there’s a transaction active when I call databaseManager.rollbackEditedRecords(), if there is I rollback also the DB transaction.

I would say in the logic of RDBMS’s a rollback undoes any edited records, deleted records and added records. Servoy (internal) transactions should act the same.

This is how it should be. Nicolas trick is cool, but it seemts a workaround.

patrick:
Nicolas trick is cool, but it seemts a workaround.

Yes it is :)
Maybe in the future the servoy team could change the behaviour.

Anyone created a case for this in the support system?

A similar problem seems to be databaseManager.hasRecordChanges. If have a form with a tabpanel showing related records. For the tabpanel I ask

databaseManager.hasRecordChanges(tabPanelForm.foundset)

If I add new records to the relation, the above results in false when it should return true… Is hasRecordChanges limited to changes of records that already existed?

Thanks for all the input. I am going to log this with support. I am still looking for a workaround to “user proof” my solution and to finish the project.

I agree that a rollbackeditedrecords should also clear the newly added records. I am using a SQL Server 2000 database and db identity.

To make certain that I did not have any conflicting with what I was trying to accomplish I created a new solution with one table view on a form and used only the methods to add, rollback, and save with no other methods and got the same results.

pbakker asked:

Anyone created a case for this in the support system?

I just did.

Thanks,

Jim

This has bin adressed in Servoy 3.1.5 and 3.5 beta