CRM2011 – Update description with resolution field when close an Incident

Today I had to update the description in my incident entity with a resolution from Close Case Dialog.
resolution
There are a two ways to do that:
First: Create a custom dialog and use this one to close the incident. In the new dialog we can create the steps and to decide what field upgrade. I found this good tutorial to do that:

Replace Resolution Dialog

In this tutorial is explain the way to implement the new Dialog and the way to mapping the resolution field with description or another fields.
But this solution is too long and the effort is to much for my requirements.

Another fast solution is to use the “Close” message of “incident” is the message to take advantage of this, and running at “Pre Validation” stage of execution will ensure your changes get applied to the case before it is closed by CRM and no longer updateable.

Here is a screenshot illustrating the appropriate message and step to subscribe to
screen

The one thing that you may not expect is the entity you will actually get passed within your plugin will not actually be incident (case) but will actually by Incident Resolution:

IPluginExecutionContext context = localContext.PluginExecutionContext;
Entity incidentResolution = (Entity)context.InputParameters["IncidentResolution"];

From this you can get the case to update using a standard retrieve to get the Incident associated at the IncidentResolution:

Entity incident = localContext.OrganizationService.Retrieve("incident", ((EntityReference)incidentResolution["incidentid"]).Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));


Now we can update the description entity with the Resolution field:

IOrganizationService service = localContext.OrganizationService;
Incident newService = null;
newService = new Incident<
{
Id = _entityToValidate.Id,
LogicalName = _entityToValidate.LogicalName
};
newService.Description += incidentResolution.Subject;
service.Update(newService);

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...