Plugins and Event Execution Pipeline in Dataverse

Plugins in Dataverse

Plugin is a custom event handler that executes in response to a specific event raised while processing a Dataverse operation. It is a business logic implemented using a custom class as a Class Library in the .NET framework. It is compiled into an assembly that can be uploaded and registered in Dataverse. One or more combined plugin classes are compiled within an assembly that can be registered on specific events within the Dataverse plugin event framework. When the target event occurs on the specified data processing operation, the plugin registered on the event gets executed. Get more curated details of the plugin from the Microsoft documentation here.

Event Execution Pipeline

Plugins and Event Execution Pipeline in Dataverse

  1. Pre-Validation
  2. Pre-Operation
  3. Main-Operation
  4. Post-Operation

Pre-Validation

The plugins registered in this pre-event execute outside the database transactions and before security validations like permission, calling, or logged-in user check. The stage number for Pre-Validation is 10. It executes before the occurrence of the Main-Operation, an internal server operation. In this event, we can add some logic to cancel or roll back the operation, which tends to happen. The plugins in the Pre-Validation stage run in synchronous mode.

Pre-Operation

The Plugins under this stage are executed inside the database transaction before the Main-Operation. The stage number for Pre-Operation is 20. This stage includes security checks and validations. Canceling operations is not recommended in Pre-Operation because the cancellation may trigger rollbacks and it may impact performance. The plugins in this stage run in synchronous mode. They are changing the value of the entity mentioned in the message before the main operation can be achieved through this stage.

Main-Operation

A Platform core operation held internally. It is stage 30. No custom plugins can be registered at this stage.

Post-Operation

The plugins registered in this stage run after the execution of the main operation, and it is held within the database transaction. The stage number for Post-Operation is 40. This stage modifies the message before it is returned to the caller. This stage shouldn't be used to modify the entity mentioned in the message because it will trigger a new update event. The plugins in this stage run in both synchronous and asynchronous modes. The asynchronous plugins may run after the database transaction. 

Pre and Post Images

Images are snapshots of the entity's attributes before and after the main operation. The value of the attributes before the update operation can be retrieved with these images. 

Two types of Images,

  • Pre-Image
  • Post-Image

Pre-Image

The value of the attributes before the main operation can be retrieved through this Pre-Image.

Post-Image

The value of the attributes after the main operation can be retrieved through this Post-Image.

The below table shows the availability of images in Pre and Post Events.

Plugins and Event Execution Pipeline

✔- Available

✖- Not Available

Points to Remember

  • The time limit for the execution of the plugin is 2 minutes; rather, it would be a synchronous or asynchronous plugin. 
  • If the plugin fails by exceeding the time limit of 2 minutes, it will throw a System.TimeoutException
  • Asynchronous plugins are queued by the Asynchronous Queue Agent and executed later by the Asynchronous Service.


Similar Articles