Capture Case Resolution data before reopening case using C#

Introduction: When we reactivate cases, the old case resolution record is set as cancelled and a new case resolution record is created, before you re open the case, you can actually store case resolution data, which you can later use when you re-close the case.


Below is the code to get case resolution data

 private void GetCaseResolutionData()
            string resolutiondata = null, Remark=null;
            try {
                EntityReference currentEntity = (EntityReference)context.InputParameters["Target"];
                Entity Case = service.Retrieve("incident", currentEntity.Id, new ColumnSet(new string[] {"statuscode"}));
                Guid CaseID = currentEntity.Id;
                string ResolutionType = Case.FormattedValues["statuscode"];  //case resolution dropdown formatted value
                int Resolutionvalue = ((OptionSetValue)Case["statuscode"]).Value; //case resolution option set value
                QueryExpression query = new QueryExpression("activitypointer");
                query.Criteria = new FilterExpression();
                query.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, CaseID);
                EntityCollection results = service.RetrieveMultiple(query);
                trace.Trace("after Query Exprrssion");
                if (results.Entities.Count >= 1)
                      resolutiondata = results.Entities[0].GetAttributeValue<string>("subject"); // resolution saved against the case
                     Remark= results.Entities[0].GetAttributeValue<string>("description"); //remarks saved against case

  Code below is to close case again with data saved as per above string

 var resolution = new Entity("incidentresolution");
            resolution["subject"] = resolutiondata;
            resolution["incidentid"] = new EntityReference { Id = caseID, LogicalName = "incident" };
            var closeIncidentRequest = new CloseIncidentRequest
                IncidentResolution = resolution,
                Status = new OptionSetValue((int)resolutionType)

Note: Case Resolution entity is not visible through advance find, for testing purpose, you can filter activities by activity type= case resolution and regarding as your case Id.

Share Story :