Introduction to Plugin

A plug-in is a custom business logic which extends the standard behavior of the dynamic platform. This server-side programming uses C# classes and MSCRM SDK to modify the behavior. Plug-ins act as event handlers and are registered to execute on a particular event in CRM.

Types of Plugins:

Synchronous Plugins:

These are the plugins which works just right after the event is triggers.

Asynchronous Plugins:

These are the plugins which works whenever the system have idle resources. It will not interrupt any operation in the execution.

Plugin Pipeline Stages:

Pre-validation:

Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage may execute outside the database transaction.

Pre-operation:

Stage in the pipeline for plug-ins that are to executed before the main system operation. Plugins registered in this stage are executed within the database transaction.

Post-operation:

Stage in the pipeline for plug-ins which are to executed after the main operation. Plug-ins registered in this stage are executed within the database transaction.

Plugin Messages:

Messages are the events on which the plugin is registered. For example, you want to run a logic whenever a account is updated.
Register your plugin with pre/post operation and with message update.

The following is the lists of messages for custom entities that support the execution of plug-ins:

  • Assign
  • Create
  • Delete
  • GrantAccess
  • ModifyAccess
  • Retrieve
  • RetrieveMultiple
  • RetrievePrincipalAccess
  • RetrieveSharedPrincipalsAndAccess
  • RevokeAccess
  • SetState
  • SetStateDynamicEntity
  • Update

For default out-of-the-box entities, there are more than 100 supported messages. Some of these messages are applicable for all the entities while some of them are specific to certain entities.

IPluginExecutionContext:

IPluginExecutionContext defines the contextual information passed to a plug-in at run-time. Contains information that describes the run-time environment that the plug-in is executing in, information related to the execution pipeline, and entity business information. Syntax is as following:

IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));
Properties:

BusinessUnitId:
Gets the GUID of the business unit that the user making the request, also known as the calling user.

Depth:
Every time a running plug-in or Workflow issues a message request to the Web services that triggers another plug-in or Workflow to execute, the depth property of the execution context is increased. Used by the platform for infinite loop prevention.

InputParameters:
The parameters of the request message that triggered the event that caused the plug-in to execute. It is a collection of parameters from record on which the plugin is triggered.

MessageName:
The name of the Web service message being processed by the event execution pipeline. Helpful to bifurcate between different messages(Create, delete, update etc..) in single class.

PreEntityImages:
It is a collection of properties of the primary entity before the core platform operation has begins.

PostEntityImages:
It is a collection of properties of the primary entity after the core platform operation has been completed.

UserId:
UserID is the GUID of the system user for whom the plug-in invokes web service methods on behalf of. This property corresponds to the SystemUserId property, which is the primary key for the SystemUser entity.

PrimaryEntityId:
PrimaryEntityId gets the GUID of the primary entity for which the pipeline is processing events. For example, if the event pipeline is processing an account, this corresponds to the AccountId attribute, which is the primary key for the Account entity.

PrimaryEntityName:
PrimaryEntityName gets the name of the primary entity for which the pipeline is processing events.

Availability of images in event pipeline:

MessageStagePre-ImagePost-Image
CreatePre-Operation NoNo
CreatePost-OperationNoYes
UpdatePre-OperationYesNo
UpdatePost-OperationYesYes
DeletePre-OperationYesNo
DeletePost-OperationYesNo

Leave a comment

Design a site like this with WordPress.com
Get started