OnRecordSave event

OnRecordSave event

Hi All,

Some times our users open a record and accidentally change the values in that record.
Im trying to prevent this by having a method to ask them if they want to save the change to the record.

I have the following method that gets called on OnRecordSave, but it does not rollback the changes to the record:

var message = ‘Record has been modified. Do you want to save it? No to rollback, Ok to save.\n’;
var ALERT = plugins.dialogs.showInfoDialog( ‘Result’, message, ‘No’, ‘Ok’);

if (ALERT == ‘No’)
{

databaseManager.rollbackTransaction()
}

if (ALERT == ‘Ok’)
{
controller.saveData();
}

Thanks for any help.

Abrahim

Hi Abrahim,

did you start a transaction when you entered the record? OnRecordSelect?

Anyway, I tried coding something similar a couple of weeks ago, and had to abandon the transaction approach. It worked well for a single user, but as soon as other clients try to save when a transactions is active, they will freeze until the first transaction is committed or rolled back.

A better approach may be to switch autosave off, and do a manually prompted save when leaving the record. I have never tried this myself, but I’m sure you’ll find some posts here on the forum…

swingman,

I have switched the autosave off, but still dont work.

Thanks,

Abrahim

Abrahim,

I never work with onRecordSave, but I wonder when your code ever commits a transaction. controller.saveData() does not commit the transaction. You do a rollback, but where is the commit? Shouldn’t your code look like this:

f (ALERT == ‘No’) {
databaseManager.rollbackTransaction() }
else {
databaseManager.commitTransaction(); }

When you start a transaction, you get a little icon (I think it is similar to an hour glass) on the bottom of the screen. Have a look at that…

I thought the little icon meaning open transaction was a bow tie…

;-)

Rich Coulombre

Thanks guys!

Abrahim