locked
Incident Resolution Plugin RRS feed

  • Question

  • Hello,

    I am writing a plugin against the IncidentResolution Entity, I can get the value of fields but how can I stop the case from being resolved if one of the values is null.  This is running in CRM 2013 SP1 so I want the OOB functionality (prompt about activities / show the case resolution box) but do not want a case resolved unless certain fields are complete.  I cannot make these mandatory as they are only required when the case is resolved.  I did try using JavaScript and catching if the state value was 5 but this does not seem to work with CRM 2013 SP1, the case was always resolved!  A sample of the code I am using is:

    public void Execute(IServiceProvider serviceProvider)
            {
                Guid incidentId = Guid.Empty;
                string incident_resolution = string.Empty;
    
                // Get the execution context from the service provider
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
     
    
                if (context.InputParameters.Contains("IncidentResolution") && context.PrimaryEntityName == "incident" && context.MessageName == "Close")
                {
                    // Get the target entity from the input parameters
                    Entity entity = (Entity)context.InputParameters["IncidentResolution"];
    
                    incidentId = ((EntityReference)entity.Attributes["incidentid"]).Id;
                    incident_resolution = entity.Attributes["description"].ToString(); // using for test purposes
    
                    if (incidentId != Guid.Empty)
                    {
                        try
                        {
                            if (incident_resolution == null)
                            {
                                // Here I want to cancel the case resolution and return the user to the current case
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new InvalidPluginExecutionException(ex.Message);
                        }
                    }
                }
            }

    Thanks in advance

    Duane

    Wednesday, October 15, 2014 10:13 AM

Answers

  • Hello,

    If some conditions are not met - just trow an exception from a plugin and case would not be resolved.


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    • Marked as answer by Duane Stead Wednesday, October 15, 2014 11:39 AM
    Wednesday, October 15, 2014 10:31 AM
    Moderator