Plugins and Event Execution Pipeline in Dataverse

Tamilarasu Arunachalam
3 min readApr 18, 2023

--

Plugins and Event Execution Pipeline in Dataverse
Photo by DongGeun Lee on Unsplash
  • Plugins in Dataverse
  • Event Execution Pipeline
  • Pre and Post Images
  • Points to Remember

Plugins in Dataverse

Plugin is a custom event handler that executes in response to a specific event raised during processing a Dataverse operation. It is a custom business logic implemented using custom class as a Class Library in .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, which 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

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

Pre-Validation

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

Pre-Operation

The Plugins under this stage are executed inside the database transaction and before the Main-Operation. The stage number for Pre-Operation is 20. This stage includes security checks and validations. Cancelling operations is not recommended in Pre-Operation because the cancellation may trigger rollbacks, and it may impact performance. The plugins in this stage runs in synchronous mode. Change 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. No custom plugins can be registered in this stage. It is the stage 30.

Post-Operation

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

Pre and Post Images

Images are the 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

✔ — Available

— Not Available

Points to Remember

  • The time limit for the execution of plugin in 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.

Originally published at https://www.tamilarasu.me on April 15, 2023.

--

--

Tamilarasu Arunachalam
Tamilarasu Arunachalam

Written by Tamilarasu Arunachalam

A Software Engineer with experience in developing applications out of Power Platform, majorly on Power Apps and Power Automate. I am a seasonal blogger too.

No responses yet