hi is still not work
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
trace.Trace("Inside try");
Entity target = (Entity)context.InputParameters["target"];
//Inheritance OBJECT
EntityReference regardingCaseRef = target["regardingobjectid"] as EntityReference;
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
QueryExpression qeRelatedTasks = new QueryExpression("incident");
qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef));
EntityCollection allRelatedTasks = service.RetrieveMultiple(qeRelatedTasks);
trace.Trace("Case title: " + regardingCase["title"]);
// update case description = all tasks completed
Entity incident = new Entity("incident")
{
Id = regardingCaseRef.Id
};
incident["description"] = "All Task Completed";
service.Update(incident);
}
catch (Exception ex)
{
throw (ex);
}
}
//get all the task that have regarding = regarding
//loop thr all task (entitycollection.entities
//and check if any task that has CSU task status not equal to completed
//if yes break out of the loop and return false
//if no write in the description all task is done
//If (task.All(x => x.TaskStatus == Task.Cometed)
// do something here
public bool AreAllRelatedTasksCompleted(EntityCollection relatedTasks)
{
if (relatedTasks.Entities.All(x => ((OptionSetValue)x["cos_csutaskstatus"]).Value == 769190000))
{
//Console.WriteLine("All task completed");
return true;
}
else
{
return false;
}
}
}