MSCRM 2011 Plugin to cancel the case

Respondido MSCRM 2011 Plugin to cancel the case

  • quinta-feira, 17 de maio de 2012 15:20
     
     

    I am trying to cancel the case through plugin based on some conditions. I am using the following code

    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 = 6;
                    req.Status = o;
                     CloseIncidentResponse resp = (CloseIncidentResponse)service.Execute(req);

    Plugin throws an error saying "Plugin terminated with an exception" But if i give o.Value=5 (to close the case), plugin closes the case.. any ideas ..

    Thanks.. 


Todas as Respostas

  • quinta-feira, 17 de maio de 2012 15:40
    Moderador
     
     Respondido Contém Código

    You cannot use the CloseIncidentRequest to cancel a case, you need to use the SetStateRequest:

    SetStateRequest ssr = new SetStateRequest()
                {
                    EntityMoniker = new EntityReference("incident", parententityid),
                    State = new OptionSetValue(2),
                    Status = new OptionSetValue(6),
                };
                service.Execute(ssr);


    Gonzalo | gonzaloruizcrm.blogspot.com