i want to close the case but it doesnt seem work.
try
{
trace.Trace("inside try");
Entity target = (Entity)context.InputParameters["target"];
//retrieve
Entity entity = service.Retrieve("task", target.Id, new ColumnSet(true));
//pointer
EntityReference regardingCaseRef = entity["regardingobjectid"] as EntityReference;
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
//retrieve multiple using query expression
QueryExpression qeRelatedTasks = new QueryExpression("task");
qeRelatedTasks.ColumnSet = new ColumnSet(true);
qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef.Id));
EntityCollection relatedTasks = service.RetrieveMultiple(qeRelatedTasks);
if (AllTaskReject(relatedTasks))
{
trace.Trace("insidebool");
Entity IncidentResolution = new Entity("incidentresolution");
IncidentResolution.Attributes["subject"] = "Incident Resolved";
IncidentResolution.Attributes["incidentid"] = new EntityReference("incident", entity.Id);
CloseIncidentRequest closeRequest = new CloseIncidentRequest();
closeRequest.IncidentResolution = IncidentResolution;
closeRequest.Status = new OptionSetValue(912450000);
// Execute the close request
service.Execute(closeRequest);
//trace.Trace("status check");
//regardingCase["cos_csucasestatus"] = new OptionSetValue(769190006);
//trace.Trace("status check 2");
//service.Update(regardingCase);
//trace.Trace("status check 3");
/* Entity incident = new Entity("incident");
incident.Id = regardingCaseRef.Id;
trace.Trace("1");
incident["cos_csucasestatus"] = new OptionSetValue(769190006);
service.Update(incident);*/
// regardingCase.Attributesk["cos_csucasestatus"] = new OptionSetValue(769190006);
}
}
catch
{
throw;
}
}
}
public bool AllTaskReject(EntityCollection relatedTasks)
{
//check all the the task if rejected continue if on task not rejected do nothing
if (relatedTasks.Entities.All(x => x.ToEntity<Task>().cos_CSUTaskStatus == cos_CSUTaskStatus.Rejected))
{
return true;
}
else
{
return false;
}