Data Integration/Migration has always been a challenge in any Dynamics CRM implementation. The native Data Import utility cannot handle the complex data migration/integration specially with complex relationships between different entities. For a long time developers have been writing applications or SSIS packages for data integration using the CRM SDK. One of the fundamental challenge with CRM SDK has been that message execution were not transnational i.e. there was no rollback possible.
Let’s take the following scenario. We need to create a contact and then associate it with its parent account records as primary contact. There are two transactions: CREATE of Contact and UPDATE of Account. With ExecuteMultipleRequest command of SDK, it was possible to send both these messages together to CRM for execution. But what was not possible was to rollback the whole transaction if the CREATE succeeds but the UPDATE fails.
Dynamics CRM 2015 Update 1 SDK has introduced ExecuteTransactionRequest which allows to execute multiple requests in a transaction, which means if any one of these requests execution fails the whole transaction will be rolled back.
By definition, a transaction is a sequence of operations performed as a single logical unit of work. Transaction is fundamental for data integrity and transactions must exhibit Atomicity, Consistency, Isolation, and Durability (ACID) properties, to qualify as a transaction.
The following code illustrates how ExecuteTransactionRequest can be used:
The Transnational batch works on the following principles:
- It executes two or more organization service requests in a single database transaction.
- The message requests in the Requests collection are executed in order as they appear in the collection, where the element at index 0 is executed first.
- If any one of the requests fail and the transaction is rolled back, any data changes completed during the transaction are undone.
- Set ReturnResponses to true to get back a collection of responses.
- The maximum allowed Batch size is 100 i.e. up to 100 requests per transaction request is allowed.
- CRM online has a throttling of 2 concurrent batch requests. If we send more than 2 simultaneous batch requests to CRM online server, we will get an error indicating the server is busy.
- We can mix CreateRequest and UpdateRequest in the same Transactional Request batch.