Administering an Encyclopedia volume : About composite operations and transactions : Working with a transaction
 
Working with a transaction
In a composite Administrate operation, the failure of any single operation does not invalidate operations that complete successfully before the failure. To require that all operations succeed before any updates can occur, create a transaction.
In the following example, the two principal operations are CreateGroup and UpdateUser. UpdateUser consists of several additional operations, such as assigning security roles to users and adding those same users to two groups, including the group that this operation creates. The following operation performs all UpdateUser operations on every user in the NameList element:
<SOAP-ENV:Body>
<Administrate>
<AdminOperation>
<CreateGroup>
<Group>
<Name>Marketing Directors</Name>
<Description>Direct reports to the Marketing VP
</Description>
<Group>
</CreateGroup>
<Transaction>
<TransactionOperation>
<UpdateUser>
<UpdateUserOperationGroup>
<UpdateUserOperation>
<AddToGroupsByName>
<String>Marketing Directors</String>
<String>All Employees</String>
</AddToGroupsByName>
<AddToRolesByName>
<String>Administrator</String>
<String>Management Staff</String>
</AddToRolesByName>
</UpdateUserOperation>
</UpdateUserOperationGroup>
<NameList>
<String>Claude Normand</String>
<String>Akiko Takagishi</String>
<String>Colleen O’Grady</String>
</NameList>
</UpdateUser>
</TransactionOperation>
</Transaction>
</AdminOperation>
</Administrate>
</SOAP-ENV:Body>
As with other composite operations, CreateUser transactions execute sequentially. The difference is that any failure within a transaction causes the entire transaction to fail. For example, if AddToRolesByName succeeds for Claude Normand and Akiko Takagishi but fails for Colleen O’Grady, no users receive administrative privileges. All users’ privileges revert to their previous settings and the entire AddToGroupsByName sequence fails. CreateGroup comes before the transaction. If CreateGroup succeeds, the operation adds the new group to the database because CreateGroup completed before the failure. Operations that follow the failed transaction do not run.