Plugin Event Execution PipelinePlugin Event Execution Pipeline

Microsoft Dynamics CRM (MSCRM) provides a powerful framework for creating custom functionality and extending the out-of-the-box features of the platform. One of the key ways to extend the functionality of MSCRM is through the use of plugins, which are custom codes that can be executed in response to specific events or actions within the platform.

In this article, we will explore the plugin event execution pipeline in MSCRM, including what it is, how it works, and how you can use it to extend the functionality of your MSCRM instance.

What is the Plugin Event Execution Pipeline?

The plugin event execution pipeline is the sequence of steps that MSCRM follows when executing a plugin in response to an event or action within the platform. The pipeline consists of several stages, each of which performs a specific task or set of tasks as the plugin is executed.

How Does It Work?

  1. Event Registration:
    • Plugins are registered to specific events on entities (e.g., create, update, delete) using the Plugin Registration Tool or through code.
    • You specify the entity, the event, and the stage at which the plugin should execute.

  2. Pipeline Stages: The pipeline consists of multiple stages, which can be grouped into two main categories: Pre-Operation and Post-Operation.
    • Pre-Validation (Outside Database Transaction):
      • Executes before the main system operation.
      • Commonly used for early validation, ensuring the data meets specific criteria before processing.

    • Pre-Operation (Within Database Transaction):
      • Executes before the main system operation but within the database transaction.
      • Used for modifying the input parameters or performing business logic that needs to occur before the core operation.

    • Main Operation:
      • The core operation is performed by the system (e.g., creating, updating, deleting the record).

    • Post-Operation (Within Database Transaction):
      • Executes after the main system operation but within the database transaction.
      • Used for modifying the output parameters or performing additional business logic.

    • Post-Operation (Outside Database Transaction):
      • Executes after the main system operation and outside the database transaction.
      • Used for actions that do not require transactional consistency, such as calling external services or sending notifications.

  3. Execution Context:
    • The execution context provides information about the current operation, including the input parameters, output parameters, pre and post-images of the entity, and the message (e.g., Create, Update, Delete) being processed.
    • Plugins can access and manipulate this context to implement their business logic.

  4. Transaction Handling:
    • Plugins registered in the Pre-Operation and Post-Operation (within the transaction) stages run within the same database transaction as the main operation. If any plugin fails, the entire transaction is rolled back.
    • Plugins registered in the Post-Operation (outside the transaction) stage do not affect the main transaction and run independently.

Example Workflow

  1. Create Operation Initiated:
    • A user creates a new account record in Dynamics 365 CRM.
  2. Pipeline Triggered:
    • The pipeline is triggered for the Create event on the Account entity.
  3. Pre-Validation Stage:
    • Any plugins registered for Pre-Validation execute. If a plugin raises an exception, the operation is aborted.
  4. Pre-Operation Stage:
    • Plugins registered for Pre-Operation execution. They can modify the input parameters or perform custom logic.
  5. Main Operation:
    • The system performs the main operation (creating the account record).
  6. Post-Operation Stage:
    • Plugins registered for Post-Operation (within the transaction) execute. They can modify the output parameters or perform additional business logic.
  7. Post-Operation (Outside Transaction) Stage:
    • Plugins registered for Post-Operation (outside the transaction) execute. They perform actions that do not require transactional consistency.
  8. Completion:
    • The operation completes, and the record is created if no exceptions are raised.

Once the plugin is registered in MSCRM, it will be executed in response to the event that it is designed to respond to. The plugin can perform any desired functionality, such as updating records, sending emails, or triggering workflows.

Leave a Reply

Your email address will not be published. Required fields are marked *