Reputation: 870
I have 2 plugins registered on the same pipeline stage (post operation) and triggers on the same entity Entity A (create event).
When plugin 1 triggers on Entity A (create event) and make changes to Entity B and another plugin 2 triggers on Entity A (create event) and while making changes to Entity A an exception was thrown.
Does the changes that plugin 1 made on Entity B get rolled back since both plugins triggers on the same entity and they have the same pipeline stage OR the changes plugin 1 made to Entity B remain and will not be rolled back?
Upvotes: 1
Views: 1030
Reputation: 17562
Depends on the plugin transaction.
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 (pre-operation) 20 and (post-operation) 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.
In your case if the plugins are chained together, and the second one is synchronous the exception from plugin 2 will bubble up to plugin 1. If both plugins are inside a transaction the actions from both plugins are rolled back.
Upvotes: 2