Resolve Case without Case Resolution Dialog


Resolve Case without case Resolution dialog pop-up:

  • Create a Boolean attribute, place it on form and set visible false.
  • Create a Ribbon Command on Case using Ribbon Workbench.
  • case1
  • Create a client side script (java script) to update the Boolean flag to True. Bind it to the Command button created earlier.
//Called from the Custom Command Button to Resolve the Case without Dialog pop-up
function ResolveCaseCustom() {
try {
Xrm.Page.getAttribute(“new_iscaseresolved”).setValue(true);
Xrm.Page.data.entity.save();
}
catch (error) { Xrm.Utility.alertDialog(error.message, null); }
}
  • Now Create Post Update Plugin with logic to do the Case resolution. Keep in mind that you need to update the Boolean flag to false in plugin because if someone activated the case and click on Resolve it won’t function as desired. Hence we need to update the Boolean field to False.
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Samples
{
public class PostUpdateCase : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity)
{
Entity entity = (Entity)context.InputParameters[“Target”];

if (entity.LogicalName != “incident”)
return;

try
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

//If Case Resolved flag check
if (entity.Attributes.Contains(“new_iscaseresolved”) && entity.Attributes[“new_iscaseresolved”] != null && Convert.ToBoolean(entity.Attributes[“new_iscaseresolved”]))
{
//Update the Is Resolve Flag to False.
Entity updateCase = new Entity();
updateCase.LogicalName = “incident”;
updateCase.Id = entity.Id;
updateCase.Attributes.Add(“new_iscaseresolved”, false);
service.Update(updateCase);

// Create the incidentresolution.
Entity caseResolution = new Entity(“incidentresolution”);
caseResolution.Attributes.Add(“incidentid”, new EntityReference(“incident”, entity.Id));
caseResolution.Attributes.Add(“subject”, “Closed”);
// Close the incident with the resolution.
CloseIncidentRequest req = new CloseIncidentRequest();
req.IncidentResolution = caseResolution;
req.RequestName = “CloseIncident”;
OptionSetValue o = new OptionSetValue();
o.Value = 5;
req.Status = o;
CloseIncidentResponse resp = (CloseIncidentResponse)service.Execute(req);
}
}
catch (InvalidPluginExecutionException)
{
throw;
}
}
}
}
}

 

  • While registering the Plugin make sure the Plugin would get fired only when the Flag is updated.
 case2

 

  • That’s it. Done.

 

About Kishore Dhanekula

MS Dynamics CRM and .NET Architect
This entry was posted in CRM, Java Script, Ms Dynamics CRM 2013, MS Dynamics CRM 2015. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s