Hi,
To fire a plugin when an incident is resolved we need to register the plugin in
Close message for the incident entity.
And in the input parameters of the context we need to check for IncidentResolution.
This entity is a special entity that holds the information about the incident record that is being closed.
The sample plugin below gets the actual end attribute value of IncidentResolution and subtracts created on attribute value of Incident to get the duration and updates the duration (custom field) in the case being resolved.
public void Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("IncidentResolution")) { Entity incidentResolution = (Entity)context.InputParameters["IncidentResolution"]; Guid relatedIncidentGuid = ((EntityReference)incidentResolution.Attributes["incidentid"]).Id; DateTime actualEnd = DateTime.Now; if (incidentResolution.Contains("actualend")) { actualEnd = (DateTime)incidentResolution.Attributes["actualend"]; } // Obtain the organization service reference. IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); // Get created on of incident Entity retrievedIncident = service.Retrieve("incident", relatedIncidentGuid, new ColumnSet(true)); DateTime createdOn = (DateTime)retrievedIncident.Attributes["createdon"]; TimeSpan totalTimeSpent = actualEnd.Subtract(createdOn); Entity incident = new Entity("incident"); incident.Id = relatedIncidentGuid; incident.Attributes["new_duration"] = totalTimeSpent.TotalMinutes; service.Update(incident); } }
The helpful post
http://varghesedanny.com/2011/02/24/plug-in-when-case-incident-is-closed/
Reblogged this on Dynamicsofdynamicscrm and commented:
Very nice post by CRM Guru Nishant
LikeLike
Reblogged this on CRM Backlog.
LikeLike
Hi Buddy,
Nicely Done.
I am learning CRM and the next task I m trying is to update a custom entity Resolution field with Case Resolution whenever the case is resolved.
Can you please help me with the same.
LikeLike