locked
Case close on click of Resolve button programmatically RRS feed

  • Question

  • Hi,

    I am trying to close the case  programmatically when i click Resolve button on case entity .  I am  triggering a plugin which fires on close message  and in the code there is no error and it's working fine . But when i try to open the  case i found that status is  still active and when i try to close case again  after clicking on resolve button i am getting error as in the below

    screen shot. I am using this example in the url to close the case

    http://mileyja.blogspot.in/2011/08/close-case-using-jscript-or-net-in.html

     .


    Abhishek

    Thursday, September 12, 2013 11:54 AM

Answers

  • Already it's being getting closed by inbuild JS from CRM so no need to close again.


    Abhishek

    • Marked as answer by Abhisinha17 Tuesday, September 17, 2013 12:57 PM
    Tuesday, September 17, 2013 12:57 PM

All replies

  • Hi,

    There seem to be several things going on at once here. Can you please clarify:

    Does the case ever actually get closed (try enabling audit on the case entity to confirm)?

    What plugin message is your plugin attached to?

    What logic are you performing in the plugin?


    Michael Palmer
    xRMPalmer     @MJFPalmer     Rockstar365

    Thursday, September 12, 2013 12:02 PM
  • Hi,

    Plugin there is no error and it's working fine. It's running on close message and pre operation of case entity and i am using the code given at above url .


    Abhishek



    public partial class CloseCase : IPlugin
        {
    
            public void Execute(IServiceProvider serviceProvider)
            {
                // Exit if any of the following conditions are true:
                //  1. plug-in is not running on the 'incident' entity
                //  2. plug-in is not running synchronously (context.Mode = Synchronous)
                //  3. plug-in is not running in the 'pre-processing' stage of the pipeline (context.Stage = BeforeMainOperationOutsideTransaction)
                //  4. plug-in is not running in a 'parent' pipeline (context.InvocationSource = Parent)
                //  5. plug-in is not running on the 'Close', or 'SetStateDynamicEntity' messages
    
    
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                // Get a reference to the Organization service.
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
    
                // Get a reference to the tracing service.
                ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                try
                {
    
                    if (context.Depth > 1)
                    {
    
                        return;
                    }
                    else
                    {
    
    
                      
    
                            //Entity entity = (Entity)context.InputParameters["Target"];
    
    
    
    
                          
                                if (context.MessageName == "SetStateDynamicEntity")
                                {
                                    HandleSetStateDynamicEntity(context, service);
                                }
    
    
    
                                else if (context.MessageName == "Close")
                                {
                                    HandleClose(context, service);
                                }
    
    
    
    
                            
    
                        
                    }
                }
    
                catch (Exception ex)
                {
    
                    throw new InvalidPluginExecutionException("The plug-in terminated with an error.", ex);
                }
    
            }
    
    
    
           
    
            
            private void HandleClose(IPluginExecutionContext context,IOrganizationService service)
            {
                if (context.InputParameters.Contains("IncidentResolution"))
                {
                     Entity entity = (Entity)context.InputParameters["IncidentResolution"];
                  
                       
                        if (entity.Contains("incidentid"))
                        {
                           
                                EntityReference incidentid = (EntityReference)entity["incidentid"];
    
      CloseIncident(incidentid , context, service);
    
                                                        }
                        }
                    }
                
    
     private void CloseIncident(Guid parententityid, IPluginExecutionContext context, IOrganizationService service)
            {
    
    
                try
                {
    
                    //SetStateRequest setState = new SetStateRequest();
                    //setState.EntityMoniker = new EntityReference("incident", parententityid);
                    //setState.State = new OptionSetValue();
                    //setState.State.Value = 1;
                    //setState.Status = new OptionSetValue();
                    //setState.Status.Value = 5;
                    //SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
                  
    
                    Entity caseResolution = new Entity("incidentresolution");
                    caseResolution.Attributes.Add("incidentid", new EntityReference("incident", parententityid));
                    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 (Exception ex)
                {
    
                    throw new InvalidPluginExecutionException("The plug-in terminated with an error.", ex);
                }
    
            }
    
    }
    
    
    }
    
    
    
    
    

    • Edited by Abhisinha17 Thursday, September 12, 2013 12:52 PM Update
    Thursday, September 12, 2013 12:09 PM
  • Hi,

    Would you please post the complete Plugin code ? are you performing any update in code after case resolution?

    Thanks!

    Thursday, September 12, 2013 12:12 PM
  • Observe that the blog says that the JScript operation is in asynchronous mode. I guess you were testing it immediately and the Case might not have closed by then. The async operation takes place in the background and might have completed the case closure by the time you hit the Resolve button again. That is why you have this Error.

    If you are not trying to close the case again in the plugin but have some other logic on case closure then that shouldn't be a cause of trouble.

    I guess that you are looking for the case closure to happen synchronously, and that would require a change in your JScript.

    Hope this helps!


    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    Thursday, September 12, 2013 12:15 PM
  • I have posted the code above.

    Abhishek


    • Edited by Abhisinha17 Thursday, September 12, 2013 1:38 PM Update
    Thursday, September 12, 2013 1:08 PM
  • Already it's being getting closed by inbuild JS from CRM so no need to close again.


    Abhishek

    • Marked as answer by Abhisinha17 Tuesday, September 17, 2013 12:57 PM
    Tuesday, September 17, 2013 12:57 PM