Trigger plugin on Action Execution in Dynamics CRM

Hi ,

I am going  to show in the following steps how to trigger plugin on Action execution in CRM

Steps

1) Create Action

CreateAction

2) Register plugin

RegisterPlugin

3) Call Action

The following code will show how to call the action using C#

OrganizationRequest callActionRequest = new OrganizationRequest("qdrn_setcustomervip");

callActionRequest["Target"] = new EntityReference("contact", {GUID});

OrganizationResponse callActionResponse = service.Execute(callActionRequest);

Get a Reference to an Instance of Organization Service Inside Plugins

public void Execute(IServiceProvider serviceProvider)
{

// Obtain the execution context from the service provider.

IPluginExecutionContext context = (IPluginExecutionContext)

serviceProvider.GetService(typeof(IPluginExecutionContext));
// Obtain the organization service reference.

IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

}