I need to update the project owner using PSI, since i need to make it an automatic process. I have the following sets of codes for changing the project owner but both of them have not worked.
Following is the first way which i have already tried
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;
}
Following is the second way which i have already tried
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.