Sunday 4 October 2015

Trigger a plugin when a case (incident) is resolved in CRM

Hi,

To trigger a plugin when an incident is resolved we need to register the plugin on 'Close' message for the incident entity.

And in the input parameters of the context we need to check for IncidentResolution.

You can get the case id from Incident Resolution entity by using the following code.

IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("IncidentResolution"))
{
     Entity incidentResolution = (Entity)context.InputParameters["IncidentResolution"];
     Guid relatedIncidentGuid = ((EntityReference)incidentResolution.Attributes["incidentid"]).Id;
}

IncidentResolution is a special entity that holds the information about the incident record that is being closed.

Hope this helps.

--
Happy CRM'ing
Gopinath

No comments:

Post a Comment