none
Project Server 2013 : How to Change Project owner Using PSI RRS feed

  • Question

  • Hi,

    I have the following sets of codes for changing the project owner but both of them have not worked.

    1>

    private static bool UpdateProjectOwner()
    {
       bool projUpdated = false;
       try
       {
         User newOwner = projContext.Web.SiteUsers.GetByLoginName(Username);
         Guid ProjectGuid = ProjectUID;
         //Console.Write("\nUpdating owner to {1} on project: {0} ...," ProjectGuid, Username);
         DraftProject draftProjectToUpdate = projContext.Projects.GetByGuid(ProjectGuid).CheckOut();
         draftProjectToUpdate.Owner = newOwner;
         QueueJob qJob = draftProjectToUpdate.Update();
         projContext.Load(qJob);
         projContext.ExecuteQuery();
         JobState jobState = projContext.WaitForQueue(qJob, timeoutSeconds);

          QueueJob qJob2 = draftProjectToUpdate.CheckIn(false);
          projContext.Load(qJob2);
          projContext.ExecuteQuery();
          JobState jobState2 = projContext.WaitForQueue(qJob2, timeoutSeconds);
         }
         catch (Exception ex)
         {
           Console.ForegroundColor = ConsoleColor.Red;
           Console.WriteLine(ex.Message);
           Console.ResetColor();
          }
       return projUpdated;
    }

    2>

    String projectOwnerIDstrNew = Convert.ToString(dr["ProjectOwnerUID"]);                        
    String projectOwnerIDstrOriginal = Convert.ToString(project_Ds.Project[0].ProjectOwnerID);
    if (!projectOwnerIDstrNew.Equals(projectOwnerIDstrOriginal))
    {                             
     Guid ownerID = new Guid(projectOwnerIDstrNew);
     project_Ds.Project[0].ProjectOwnerID = ownerID;
     project_Ds.AcceptChanges();

    bool managerChanged = true;

    }

    Is there any mistake in these above functions ?

    If Not, then is there any other way of updating the project owner with help of PSI.




    Wednesday, April 29, 2015 8:21 AM

Answers

  • Abhishek,

    In 2 - The line calling AcceptChanges gets rid of all your changes - remove this line and try again.

    In 1 - You should Publish your project otherwise you won't see the changes unless you check-out the draft.

    Cheers,

       James.


    James Boman BSc. MCP:EAD -



    Friday, May 8, 2015 7:07 AM

All replies

  • Hey there Abhishek,

    Helping you would be easier with an actual error message rather than "not worked"

    That being said, looking at your code example 1 it should be close to working.  

    The second example doesn't work because you are never actually updating Project Server and the call to AcceptChanges() actually removes the actionable updates from the dataset.

    Cheers,

       James.


    James Boman BSc. MCP:EAD -

    Thursday, May 7, 2015 5:43 AM
  • Hey James,

    Sorry i missed some codes in the second set.

    the complete code is as such

    String projectOwnerIDstrNew = Convert.ToString(dr["ProjectOwnerUID"]);                        
    String projectOwnerIDstrOriginal = Convert.ToString(project_Ds.Project[0].ProjectOwnerID);
    if (!projectOwnerIDstrNew.Equals(projectOwnerIDstrOriginal))
    {                             
     Guid ownerID = new Guid(projectOwnerIDstrNew);
     project_Ds.Project[0].ProjectOwnerID = ownerID;
     project_Ds.AcceptChanges();

    ConfirmProejctCheckedIn(ProjUid, project, queue);
    project.CheckOutProject(ProjUid, Sessionid, SessionDis);

    jobid = Guid.NewGuid();
    project.QueueUpdateProject(jobid, Sessionid, project_Ds, false);

    jobid = Guid.NewGuid();
    project.QueuePublish(jobid, ProjUid, true, string.Empty);

    jobid = Guid.NewGuid();
    project.QueueCheckInProject(jobid, ProjUid, true, Sessionid, SessionDis);

    bool managerChanged = true;

    }

    And, as i have written "Not Working", not any detail exception because the code is not throwing any exception.

    It gets executed successfully, but changes doesn't get reflected.

    Thanks,

    Abhishek

    Friday, May 8, 2015 4:35 AM
  • Abhishek,

    In 2 - The line calling AcceptChanges gets rid of all your changes - remove this line and try again.

    In 1 - You should Publish your project otherwise you won't see the changes unless you check-out the draft.

    Cheers,

       James.


    James Boman BSc. MCP:EAD -



    Friday, May 8, 2015 7:07 AM
  • Thanks James,

    I remove the line AcceptChanges, it worked.

    Thanks,

    Abhishek

    Friday, May 8, 2015 8:25 AM
  • Hey James,

    Removing AcceptChanges sorted out my existing problem but dataset.Getchanges created a new problem for me.

    Using the codes i am now able to change the project owner.

    The case is , when the dataset for the project is exceeding 1000 rows i am using dataset.getchanges function and passing the dataset only with changes to the UpdateProject function, project owner is getting changed but when i am opening my schedule in MPP i find so many changes in schedule.

    I can find overallocation of resources as well. I can track this as i have base-lined my schedule in beginning.

    The dataset.Getchanges function is messing my schedule. I can't go with this, as we are dealing with live projects in my organizations and respective managers will not be happy if schedule gets tampered.

    Thanks,

    Abhishek


    Monday, May 11, 2015 4:17 AM
  • That seems like a different problem - you might want to open a new forum thread for that, and post some more information in addition to 'so many changes'.

    Cheers,

    J.


    James Boman BSc. MCP:EAD -

    Monday, May 11, 2015 6:58 AM