Work Management service in SharePoint 2013 (4): What is in it for developers?

Even if there isn’t much developer documentation out there, WMA has one of the best and cleanest APIs in the SharePoint world, with equally good SSOM and CSOM implementations. Now, this is something that SharePoint developers have been asking all along – that CSOM APIs get more power – and Microsoft is delivering on its promise. A drawback here is that there are no REST endpoints for WMA API, so you are stuck with CSOM on the client side, for better or worse.

SSOM side API can be found in

Microsoft.Office.Server.WorkManagement.dll (in GAC)

CSOM side API can be found in

Microsoft.SharePoint.WorkManagement.Client.dll (in Hive15/ISAPI)

Since the both development models are actually parallel, the examples below will be in SSOM, but they can be 1:1 translated to CSOM side (the last example in this post will be CSOM).

Namespaces and classes

UserSettingsManager is the first thing you will want to initialize when working with task aggregation. It contains all of the user-related WMA information, like Locations, important Locations, timeline settings (how does the timeline looks like for a user), etc.

Microsoft.Office.Server.WorkManagement.UserSettingsManager usm = new UserSettingsManager(context);

//Get all locations
LocationClientCollection allLocations = usm.GetAllLocations();

UserOrderedSessionManager is used to manage WMA sessions for a user. You will need to pass a SPServiceContext (for SSOM), or ClientContext (for CSOM) to the UserOrderedSessionManager constructor, to initialize a session manager.

//Gets the session manager and create session
Microsoft.Office.Server.WorkManagement.UserOrderedSessionManager osm = new UserOrderedSessionManager(context);

Once you have your session manager, you can create a new WMA session. There are two kinds of sessions you can create: UserOrderedSession and LocationOrientedUserOrderedSession. They are for the most part the same, just that the LocationOrientedUserOrderedSession contains location info within the tasks, and this is the type of session you will usually want to use in most of the cases.

LocationOrientedUserOrderedSession uos = osm.CreateLocationOrientedSession();

This session object will be your main tool for executing task and provider refresh related actions. You will be able to create, edit, and delete tasks, to start a provider refresh, or Exchange sync, and a whole lot of the other cool things that can be done with tasks. In the next articles, we are going to look at some of them.