Project Server 2013:如何使用PSI更改项目所有者

时间:2015-04-30 04:56:57

标签: ms-project psi

我需要使用PSI更新项目所有者,因为我需要将其设为自动过程。 我有以下几组代码来更改项目所有者,但两者都没有用。

以下是我已经尝试的第一种方式

# To exclude hidden directories, use -name like so:
# find ... -name ".*"

# A version of find using only POSIX options:
# This might be slower for large directories (untested). Will need to be modified to list anything other than current directory.
# dirs="$(find . -type d ! -path "./*/*" ! -name ".")"

# Includes hidden directories.
dirs="$(find . -maxdepth 1 -type d ! -path .)"

numlines="$(printf "%s\n" "${dirs}" | wc -l)"
lineno="$((${RANDOM} % ${numlines} + 1))"
random_line="$(printf "%s\n" "${dirs}" | sed -n "${lineno}{p;q}")"

echo "Your selected directory: ${random_line}"

以下是我已经尝试的第二种方式

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;
}

1 个答案:

答案 0 :(得分:0)

以下是我已经尝试的第一种方式

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;
}

以下是我已经尝试的第二种方式

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;

}
相关问题