Blog Post

Project Support Blog
2 MIN READ

Project Online: Setting a Status Manager with CSOM

DeletedBrianSmith's avatar
DeletedBrianSmith
Brass Contributor
Mar 06, 2019
First published on MSDN on May 25, 2018
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");
}
Published Mar 06, 2019
Version 1.0

4 Comments

  • DavidRousselle's avatar
    DavidRousselle
    Copper Contributor

    Hello Ian Bruckner , did you manage to do it with the REST API or ProcessQuery endpoint ? I didn't. I'm thinking of doing it with an azure function 😞

    • Ian Bruckner's avatar
      Ian Bruckner
      Brass Contributor

      Nope. I happened back on this post, apparently trying again without recalling that I'd even commented on it four years ago looking for help, smiled when I saw my name, then frowned realizing I wasn't successful and am back at it many years later.

      Bummed to see the word "Deleted" in the username DeletedBrianSmith, too.

      DavidRousselle, did you end up having luck?

  • Ian Bruckner's avatar
    Ian Bruckner
    Iron Contributor

    I'm about to try my hand at this using 365 flow / power automate... but on the off hand someone already has a working example, I thought I'd check in here. Paul_Mather, maybe?

     

    Also, any update on the broader change you mentioned above in 2018 Brian-Smith