Hi Andrew,
Thanks for the response and below are the elements:-
First, I have created a field type of "Two Options" with field name is "new_isresolved" which sets Yes within that field when I click on the custom Resolve button it sets Yes into "new_isresolved" field and then saves the form.
function ResolveCaseCustom()
{
try
{
window.parent.Xrm.Page.getAttribute("new_isresolved").setValue(true);
window.parent.Xrm.Page.getAttribute("new_timerstatus").setValue("0");
Xrm.Page.data.entity.save();
}
catch (error) { Xrm.Utility.alertDialog(error.message, null); }
}
Then I have implemented a plugin which check the value of "new_isresolved". If value is Yes then make the case record Resolved, the plugin code is given below:-
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_isresolved") && entity.Attributes["new_isresolved"] != null && Convert.ToBoolean(entity.Attributes["new_isresolved"]))
{
//Update the Is Resolve Flag to False.
Entity updateCase = new Entity();
updateCase.LogicalName = "incident";
updateCase.Id = entity.Id;
updateCase.Attributes.Add("new_isresolved", 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;
}
}
}
}
}