A top-level transaction is created by sending the following message:
Transaction begin
The top-level transaction is a special transaction that is a child of the shared transaction. It can also be created with the method:
Transaction shared beginChild
The TopLevelTransaction part, used in our example, will always create a fresh top-level transaction when the view is opened. To generate new top-level transactions each time one is committed, we will use a variable part for TopLevelTransaction rather than a non-variable part and use the SharedTransaction to create new top-level transactions as required. Visually, one can always reference the SharedTransaction on a Composition Editor with the SharedTransaction part. This part is always the same instance of the singleton shared transaction, even if it is used on many different views. This behavior can be contrasted with the TopLevelTransaction part that always generates a new top-level transaction each time the view is opened.
For this reason, we will change the TopLevelTransaction part in our example to a variable part. Changing the part to a variable part will give us more control over when to create the transaction that will be used inside the variable.
There are two situations when we need to create a top-level transaction: (1) when the view first opens, and (2) each time a commit happens.
Do the following:
This ensures that when the view opens we have a top-level transaction to work with.
This connection will generate a fresh top-level transaction each time one is saved.Connect the result of the connection to the self attribute of the TopLevelTransaction variable.
There are two conections from the commited event of the TopLevelTransaction variable. One of these is to the SharedTransation part to regenerate a fresh transaction and the other is to the items attribute of the List part to ensure that is refreshed. It is important to ensure that the connection to the SharedTransaction part is the first of these two that happens.
You can also use a Business Transaction in place of the Top-Level Transaction.
Note: When using ObjectExtender with Web Connection parts you must be particularly
aware of transaction scope. When possible, the scope of the transaction
should be limited to the equivalent of one page. If this design does
not fit your application, then you will need to place a handle to the current
transaction in session data. Each Web Connection part will then need to
retrieve the current transaction from the session data. This is best
accomplished by writing scripts.