Friday, 17 April 2020

Reading all sub tasks of a Summary task using CSOM

the CSOM code to read the “Sub Tasks” for a given Summary task.
Below code snippet reads the sub tasks for the given summary tasks.
string phaseTask="<summary task name>or <id>>" ;

var draftTaskCollection = context.LoadQuery(draft.Tasks.Include(t=>t.Name, t=>t.Id, t=>t.Parent, t=>t.Start, t =>t.Duration, t=>t.IsSummary) 
       .Where(k => k.Parent != null && k.Parent.Name == phaseTask) //if its Id, then use k.Parent.Id 
context.ExecuteQuery();
if (draftTaskCollection.Any()) 
{
 foreach (var task in draftTaskCollection) 
 {
  // read the properties that you have loaded in the above query. 
  response.write(task.Name);
 }
}

In the above sinppet Just pay attention at the below line.
.Where(k => k.Parent != null && k.Parent.Name == phaseTask)
In the next blog will discuss about reading the  “All subtasks & Sub summary tasks” of a given phase(summary) task.

No comments:

Post a Comment