Previous Topic

Book Contents

Book Index

Next Topic

Undoing Changes and Aborting Transactions

To enable undoing changes, Valuemation API provides two methods, setSyncPoint to mark a point for possible future undo and doRollback that enables you to return to that point.

ApiTransaction.setSyncPoint()

Sets a syncPoint. This point represents a point in the “history” of the transaction, to which you can later return by calling ApiTransaction.doRollback if you decide that the changes made since the selected sync point should be discarded. setSyncPoint returns an identifier that can later be used to return back to the point by calling ApiTransaction.doRollback.

ApiTransaction.doRollBack(syncPointID)

Undoes changes since the specified syncPoint. That means that the operations made from this syncPoint till present are discarded. The parameter of this method is the identifier returned by ApiTransaction.setSyncPoint you called when you wanted to set the syncPoint. If no syncPoint has been set, it returns the transaction to its initial state just after it was created.

ApiTransaction.doRollBack()

Without passing syncPointID as a parameter, doRollBack undoes changes since the last syncPoint you set. If no syncPoint has been set it reverts the transaction to its initial state just after it was created or committed for the last time.

ApiTransaction.abort()

Aborts this transaction.

Note: this method can be called only once.

Example - Using transactions

We assume that you have run Valuemation and logged in correctly before starting this code. oVM variable now holds Application object. See Login Syntax for the section of the opening code.

Set oTransaction = oVM.createTransaction

' Find the catalog

set oCatalog =oVM.getCatalogs.find(oTransaction, "Person")

'sync point is set

point=oTransaction.setSyncPoint

'now you work with oCatalog created in oTransaction

'some operations might be carried out

‘.

‘.

‘.

'undoes all operations made since creating of syncpoint that we named “point”

doRollback(point)

'writes the contents of the transaction to the database and closes the transaction

oTransaction.doCommit

Comment:  After getting Application object (see above), a new transaction called “oTransaction” is created by calling createTransaction. Then, we are searching the database for a catalog called „Person“, which should result in creation of object oCatalog in our transaction that we pass as a parameter for calling the method. All operations with oCatalog you perform afterwards are not stored in the database and only remain cached in the memory of your computer until you call oTransaction.doCommit.

Having created the catalog, we also set a sync point, in our case we named it simply point. To this point that represents the initial state of the catalog we can later return by calling doRollback(point) if this is necessary.

See Also

Working in Transactions

Creating Transactions

Registering Objects to Transactions

Working with Objects in Transactions

Getting Transactions

Committing Transactions

Propagating Changes

Calling Workflows on Certain Events