Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transactions in Dynamics CRM Plugin and Web Services

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?

like image 812
Ashish Avatar asked Sep 14 '16 11:09

Ashish


People also ask

In which of these stages plugins are executed within DB transaction?

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).

What are the Web services in dynamic CRM?

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.

Which property use to check whether plug-ins may or may not execute within the database transaction of the Microsoft Dynamics 365 platform?

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 Answers

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)

  • Yes ExecuteTransactionRequest is a new CRM 2016 feature.
  • If you have CRM 2013+ you could put the logic inside an Action which supports automatic rollback. Then call the action with inputs.
  • For CRM 2011, put the logic inside a plugin. Then cause the plugin to be triggered, for example by creating a record in CRM. You can also capture inputs on the new record.
like image 77
James Wood Avatar answered Oct 12 '22 23:10

James Wood