Friday, 11 January 2019

CSOM: Working with Office365 Project Online Tasks - Part I

This article series focuses on working with office 365 project online plan schedule tasks using Client Side Object model approach.

Previously we have seen how the same operations works using JSOM approach. Both approaches are identical.

Creating Console App and Importing Package: 

SharePoint and Project Server online libraries are required to work with the project server data using CSOM model. The libraries can be downloaded from Nuget packages. The required libraries are packaged under one single package. i.e., Microsoft.SharePointOnline.CSOM

Create a visual studio console application. From Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution. From the browse tab, Find for “Microsoft.SharePointOnline.CSOM”. Select and install the package for the current solution.

The following picture depicts installing the required Nuget package.
Installing Nuget Packages for SharePoint & Project Online
Installing Nuget Packages for SharePoint & Project Online

Retrieve All Tasks: 

First let us look at retrieving all the tasks available on the project. There are two ways of retrieving tasks.

1. From the published project object – Advantage is project need not be checked-out. Since this is read only action, the tasks can be accessed this way.

2. Other way from the draft project – Trying to retrieve after checking out the project. Don’t prefer this approach if you are just viewing/accessing tasks.

The following code snippet shows retrieving tasks, but with minimal load. It gets only the properties mentioned in the load query.

Retrieve Task: 

Let's see, how a particular task can be retrieved. Task ID can be used to retrieve one particular task. And necessary properties can be accessed after retrieval. The following piece of code shows, retrieving a task by project ID and task ID. And it also shows the properties (including custom) accessed.

In the next article, let us look at more other operations for MSP project online tasks.