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.

 

Advertisements

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.

2 Responses to Resolve Case without Case Resolution Dialog

  1. Arunav Dash says:

    When we reload the case after resolving getting pop up error.

  2. Arunav Dash says:

    Unhandled exception:
    Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
    Message: This case has already been resolved. Close and reopen the case record to see the updates.Detail:

    ab85f386-373c-4d85-978b-be32d19d84ab
    -2147220273

    CallStack
    at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
    at System.Environment.get_StackTrace()
    at Microsoft.Dynamics.Solution.Common.CrmException.BuildOrganizationServiceFault(Exception innerException, Int32 errorCode, String message)
    at Microsoft.Dynamics.Solution.Common.CrmException..ctor(String message, Exception innerException, Int32 errorCode, Boolean isFlowControlException, Boolean enableTrace)
    at Microsoft.Dynamics.Solution.Common.CrmException..ctor(String message, Exception innerException, Int32 errorCode, Boolean isFlowControlException)
    at Microsoft.Dynamics.Solution.Common.CrmException..ctor(String message, Int32 errorCode)
    at Microsoft.Crm.Service.ObjectModel.IncidentService.PreValidateForUpdate(Case incident, ISecurityService securityService)
    at Microsoft.Dynamics.Service.Plugins.PreOperationIncidentUpdate.ExecuteCrmPlugin(LocalPluginContext localContext)
    at Microsoft.Dynamics.Solution.Common.PluginBase.Execute(IServiceProvider serviceProvider)
    at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass2_1.<Execute>b__0()
    at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
    at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
    at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.Execute(PipelineExecutionContext pluginContext)
    at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.UpdateWithInvocationSource(BusinessEntity entity, FilterExpression filter, Int32 invocationSource, ExecutionContext context)
    at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.Update(BusinessEntity entity, FilterExpression filter, ExecutionContext context)
    at Microsoft.Crm.BusinessEntities.BusinessProcessObject.<>c__DisplayClass192_0.<UpdateWithPipelineAndExtensions>b__0()
    at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
    at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
    at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
    at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
    at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)
    at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass2_1.<Execute>b__0()
    at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
    at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
    at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
    at Microsoft.Crm.Extensibility.ExternalMessageDispatcher.ExecuteInternal(IInProcessOrganizationServiceFactory serviceFactory, IPlatformMessageDispatcherFactory dispatcherFactory, Guid callerRegardingObjectId, Int32 invocationSource, Version endpointVersion, OrganizationRequest request, OrganizationInternalRequest organizationInternalRequest)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.DispatchRequest(OrganizationRequest request, OrganizationInternalRequest organizationInternalRequest, SdkResponseDescription responseDescription, SdkPerformanceCounterContext sdkPerformanceCounterContext)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequestRequestWithInstrumentation(OrganizationRequest request, OrganizationInternalRequest organizationInternalRequest)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequestRequestWithInstrumentationOperation(OrganizationRequest request, OrganizationInternalRequest organizationInternalRequest)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.<>c__DisplayClass17_0.<ExecuteRequest>b__0()
    at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)
    at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, UserAuth userAuth, Guid targetUserId, Guid targetCallerRegardingObjectId, UserType targetUserType, OrganizationContext context, Boolean returnResponse, Boolean checkAdminMode, Dictionary`2 optionalParameters)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequestInternal(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)
    at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)
    at Microsoft.Crm.Extensibility.InprocessServiceProxy.ExecuteCore(OrganizationRequest request)
    at Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal()
    at Microsoft.Crm.Application.Platform.ServiceCommands.UpdateCommand.Execute()
    at Microsoft.Crm.Application.Platform.EntityProxy.Update(Boolean performDuplicateCheck, Guid auditingTransactionId)
    at Microsoft.Crm.Application.Platform.EntityProxy.Update(Boolean performDuplicateCheck)
    at Microsoft.Crm.Application.Platform.EntityProxy.UpdateAndRetrieve(String[] columnSet, Boolean performDuplicateCheck)
    at Microsoft.Crm.Core.Application.WebServices.InlineEdit.CommandBase.UpdateEntity(Entity entity, Boolean retrieve)
    at Microsoft.Crm.Core.Application.WebServices.InlineEdit.SaveCommand.ExecuteCommand(String commandXml)
    at Microsoft.Crm.Core.Application.WebServices.InlineEdit.CommandBase.Execute(String commandXml, Boolean encodeValues)
    at Microsoft.Crm.Core.Application.WebServices.InlineEditWebService.Execute(Int32 command, String commandXml, Nullable`1 encodeValues)
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
    at System.Web.Services.Protocols.WebServiceHandler.Invoke()
    at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
    at System.Web.Services.Protocols.SyncSessionlessHandler.ProcessRequest(HttpContext context)
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
    at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
    at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
    at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
    at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
    at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
    at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
    at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
    at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

    This case has already been resolved. Close and reopen the case record to see the updates.
    2019-02-04T06:39:38.6555344Z
    false

    [Microsoft.Dynamics.Service.Plugins: Microsoft.Dynamics.Service.Plugins.PreOperationIncidentUpdate]
    [b986a294-28b3-e611-80f0-00155dc13602: PreOperation of Incident Update]
    Entered Microsoft.Dynamics.Service.Plugins.PreOperationIncidentUpdate.Execute(), Correlation Id: 789d539b-660e-4270-aa2e-ee097ef6b9c6, Initiating User: df5370f2-f594-e811-a94f-000d3a33c3b5
    Exception: Microsoft.Dynamics.Solution.Common.CrmException: This case has already been resolved. Close and reopen the case record to see the updates. (Fault Detail is equal to Exception details:
    ErrorCode: 0x800404CF
    Message: This case has already been resolved. Close and reopen the case record to see the updates.
    StackTrace:
    at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
    at System.Environment.get_StackTrace()
    at Microsoft.Dynamics.Solution.Common.CrmException.BuildOrganizationServiceFault(Exception innerException, Int32 errorCode, String message)
    at Microsoft.Dynamics.Solution.Common.CrmException..ctor(String message, Exception innerException, Int32 errorCode, Boolean isFlowControlException, Boolean enableTrace)
    at Microsoft.Dynamics.Solution.Common.CrmException..ctor(String message, Exception innerException, Int32 errorCode, Boolean isFlowControlException)
    at Microsoft.Dynamics.Solution.Common.CrmException..ctor(String message, Int32 errorCode)
    at Microsoft.Crm.Service.ObjectModel.IncidentService.PreValidateForUpdate(Case incident, ISecurityService securityService)
    at Microsoft.Dynamics.Service.Plugins.PreOperationIn…)., Correlation Id: 789d539b-660e-4270-aa2e-ee097ef6b9c6, Initiating User: df5370f2-f594-e811-a94f-000d3a33c3b5
    Exiting Microsoft.Dynamics.Service.Plugins.PreOperationIncidentUpdate.Execute(), Correlation Id: 789d539b-660e-4270-aa2e-ee097ef6b9c6, Initiating User: df5370f2-f594-e811-a94f-000d3a33c3b5

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