Friday, 17 April 2020

Read complete project data (Project level + Task level info) with a single request using CSOM

Read complete project data (Project level + Task level info) with a single request using CSOM for Project Server or Project Online
 way to load the whole “Project and Tasks” data for a given project in a single request to the server using CSOM. When I say complete Project and Task data it includes project properties, project level custom fields, Task properties, Task level custom fields including lookup tables and entries. Earlier, I used to hit the server for every task to read the task level level custom fields.  Below is the simple load query that brings all the data at once in a single hit.
Note: If something is not loaded and asking you for “Initialize explicitly” just add that property in the load query.

var projColl = context.LoadQuery(context.Projects
                       .Where(p => p.Id == projectGuid)
                       .Include(
                           p => p.Id,
                           p => p.Name,
                           p => p.StartDate,
                           p => p.FinishDate,                           
                           p => p.LastPublishedDate,
                           p => p.CustomFields,
                           p => p.IncludeCustomFields,
                           p => p.IncludeCustomFields.CustomFields,             
                           p => p.Tasks,
                           p => p.Tasks.Include(
                               t => t.Id,
                               t => t.Name,                               
                               t => t.Parent,
                               t => t.Predecessors,
                               t => t.Successors,
                               t => t.TotalSlack,
                               t => t.CustomFields,
                               t => t.CustomFields.IncludeWithDefaultProperties(
                                   cf => cf.LookupTable,
                                   cf => cf.LookupEntries
                               )
                           )
                       )
                   );
               context.ExecuteQuery();

No comments:

Post a Comment