Search This Blog

Sunday, November 22, 2015

CRM Plugin Introduction and Execution Pipeline Message explanation

If you have any doubt in the post please post comments. I will try to solve your problem.

Plug-ins are handlers for events fired by Microsoft Dynamics CRM. It  is to enhance or modify the standard features/behavior of CRM by injecting custom business logic into the execution of nearly any task a user performs in CRM.

Plugin code can be triggered to run when a record is created or updated or perhaps even when a group of records are queried. 

The messages are processed by the Microsoft Dynamics CRM execution pipeline for the plug-in to execute.
There are four event execution stages of pipeline that we configure a plugin to trigger

  • Pre-validation
  • Pre-Operation
  • Post-Operation(Synchronous)
  • Post-Operation(ASynchronous)

Pre-validation:
It will trigger your plugin will run before the form is validated 
Pre -operation:
It will trigger your plugin will run  after validation and before the values are saved to the database
Post operation :
It will trigger your plugin will run after the values have been inserted/changed on the database and changes reflect to the UI immedietly because the form will wait once the plugin complete its work.
Post operation Asynchronous:
It will trigger  your plugin will run after the values have been inserted/changed on the database and changes has to reflect quite some time because the plugin in process in background
Message:
It is processed by the Microsoft Dynamics CRM execution pipeline for the plug-in to execute.
The following are some of the important message.

Create:
This message is helps to trigger the plugin whenever new record is created

Plugin parameter when fire:

Context.InputParameter:

  • Target-It contains entity object

Update:
This message is helps to trigger the plugin whenever existing record is updated

Plugin parameter when fire:

Context.InputParameter:

  • Target-It contains entity object

RetrievedMultiple:
This message is helps to trigger the plugin whenever multiple records is return to the CRM(grid display,lookup control data populate.

Plugin parameter when fire:

Context.InputParameter:

  • It contains fetch xml query

Context.OutputParameter:

  • It is only available at post-operation event 
  • Only synchronous post-event and asynchronous registered plug-ins have OutputParameters populated as the response is the result of the core platform operation.
  • It contains BusinessEntityCollectio that means output of the fetch xml query entity record set(rows data).

Example:
If you want to display "name" column as concatenating  first name and last name in the entity grid. 
Configure Plugin:
Message name:Retrieved multiple
PrimaryEntity: Entity
Operation: post-operation (synch)
Plugin code
   Get the data from context.outputParameter["BusinessEntityCollection"]
   and change the value inside list by concatenating  first name and last name.
PublishAllCustomization:
This message is helps to trigger the plugin whenever you click publish button in CRM

GrantAccess-Share
This message is helps to trigger the record is share

InputParameter
context.InputParameters["PrincipalAccess"] Example:

 //Obtain the principal access object from the input parameter
                Microsoft.Crm.Sdk.Messages.PrincipalAccess PrincipalAccess = (Microsoft.Crm.Sdk.Messages.PrincipalAccess)context.InputParameters["PrincipalAccess"];
                //Then got the User or Team and also Access Control that being Granted
                //***to Get User/Team that being Shared With
                var userOrTeam = PrincipalAccess.Principal;
                var userOrTeamId = userOrTeam.Id;
                var userOrTeamName = userOrTeam.Name;
//this userOrTeam.Name will be blank since entityReference only will give you ID
                var userOrTeamLogicalName = userOrTeam.LogicalName;
RevokeAccess-Unshare
This message is helps to trigger the record is unshare


InputParametercontext.InputParameters["Revokee"]

Example:

//Unshare does not have PrincipalAccess because it removes all, only can get the revokee
                //Obtain the principal access object from the input parameter
                var Revokee = (EntityReference)context.InputParameters["Revokee"];
                var RevokeeId = Revokee.Id;

                var RevokeeLogicalName = Revokee.LogicalName; //this one Team or User

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.