I wanted to confirm my understanding on managing transactions in Dynamics CRM and check if I am missing something.
1) Transactions in CRM Plugins: The plugins registered in the Stage 20 and 40 of the Event Pipeline run under DB transaction. So if I have three plugins registered on pre/post operation of any message and if the third plugin throws an exception, the changes done by the first two plugins would also be rolled back. Is this understanding correct?
2) Transactions in CRM Web Service: In case of writing code with CRM Web Services, I can make use ExecuteTransactionRequest request and all the request messages provided with this message would run under one CRM DB transaction. This message seems to be introduced in 2016 version so what would be the ideal way to handle such scenarios prior to 2016?
Plug-ins registered in this stage are executed within the database transaction. The event triggers a Web service call and the execution is passed through the event pipeline stages (pre-event, platform core operations, post-event).
Microsoft Dynamics CRM provides two important web services that are used to access CRM from an external application and invoke web methods to perform common business data operations such as create, delete, update, and find in CRM.
You can check if the plug-in is executing in-transaction by reading the IsInTransaction property inherited by IPluginExecutionContext that is passed to the plug-in.
1) Assuming the plugins all run synchronously, then yes, all changes should be rolled back.
Inclusion in database transactions
Plug-ins may or may not execute within the database transaction of the Microsoft Dynamics CRM platform. Whether a plug-in is part of the transaction is dependent on how the message request is processed by the pipeline. You can check if the plug-in is executing in-transaction by reading the IsInTransaction property inherited by IPluginExecutionContext that is passed to the plug-in. If a plug-in is executing in the database transaction and allows an exception to be passed back to the platform, the entire transaction will be rolled back. Stages 20 and 40 are guaranteed to be part of the database transaction while stage 10 may be part of the transaction.
Any registered plug-in that executes during the database transaction and that passes an exception back to the platform cancels the core operation. This results in a rollback of the core operation. In addition, any pre-event or post event registered plug-ins that have not yet executed and any workflow that is triggered by the same event that the plug-in was registered for will not execute.
2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With