Project Online: Setting a Status Manager with CSOM


Just a quick post today to share something that might help scenarios where you need to change a status manager for a task.  As you may well know, it isn't possible to just select anyone to be a status manager for a task – and even in the client application you don’t see people in the Status Manager drop down unless they are already a status manager in the plan – and they only get there by having opened the plan and making assignments (and hence being the status manager for the new task/assignment).  Hopefully there will be a broader change coming – but a recent change in Project Online does bring this a step closer.

You still (as of 5/25) can’t set just anyone programmatically as a status manager using CSOM – they have to be ‘on the list’ – so will need to have opened the plan as mentioned above – but you can set anyone to be an owner (permissions allowing of course).  And guess what?  That gets them on the list!  So if you set the person who you want to be a status manager to be the owner of the plan – you can then set them as a status manager!  You’d probably then want to set the original owner back again.

In code here is a snippet that shows how you might approach this (I don’t set the owner back here – so if you wanted to do that you’d need to persist the actual owner).  This sample could be added as a class in the Github sample at https://github.com/OfficeDev/Project-Samples/tree/master/Create-Update-Project-Samples.  For brevity I’ve stripped out some error checking.

public static void ReadAndUpdateStatusManager()
{
// Load csom context
context = GetContext(pwaInstanceUrl);


            // Retrieve publish project named "New Project"
// if you know the Guid of project, you can just call context.Projects.GetByGuid()
csom.PublishedProject project = GetProjectByName(projectName, context);
csom.DraftProject draft = project.CheckOut();


            draft.Context.Load(draft.Owner);
draft.Context.ExecuteQuery();
draft.Context.Load(draft.Tasks);
draft.Context.ExecuteQuery();


            foreach (var task in draft.Tasks)
{
draft.Context.Load(task.StatusManager);
}


            draft.Context.ExecuteQuery();

// We get the user we want to be our status manager


            User StatusManager = context.Web.SiteUsers.GetByLoginName("i:0#.f|membership|<username goes here>@<and tenant here>.onmicrosoft.com");
context.Load(StatusManager);
context.ExecuteQuery();

// And set our user as the Owner


            draft.Owner = StatusManager;

            foreach (var task in draft.Tasks)
{
try
{
if (!task.IsSummary)
{

// Then we can set our new Owner as a Status Manager
task.StatusManager = draft.Owner;
}
}
catch (Exception ex)
{
Console.Write(string.Format("Error setting Status Manager:", ex.Message));
}
}

// Publish and check in the project
csom.JobState jobState = context.WaitForQueue(draft.Publish(true), DEFAULTTIMEOUTSECONDS);
JobStateLog(jobState, "Updating project");
}


Comments (0)

Skip to main content