更新任务状态进度 Project Server 2013

Update Task Status Progress Project Server 2013

我尝试使用项目服务器 2013 CSOM 更新任务状态进度(状态分配),但出现 "Unknown Error" 异常和以下 StackTrace:

at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Limitless.Components.Project2013.ProjectComponent.UpdateTask(ProjectServerConnection connection, Guid ProjectUID, List`1 data)

ProjectContext context = GetProjectContext(connection);
// Get the user name  and their assignments
EnterpriseResource self = EnterpriseResource.GetSelf(context);
context.Load(self, r => r.Name, r => r.Assignments
    .IncludeWithDefaultProperties(a => a.Project, a=>a.Comments));
context.ExecuteQuery();
foreach(var item in self.Assignments)
{
    Entities.Task task = data.Where(t => t.ID == item.Id).SingleOrDefault();
    if(task!= null)
    {
        item.PercentComplete = (short)task.PercentComplete;
        item.Comments = "comment";
    }
}

// Update the assignments and submit the status updates.
self.Assignments.Update();
self.Assignments.SubmitAllStatusUpdates("By PS Web App");
context.ExecuteQuery();

我在共享点日志中找不到任何错误。它是全新安装的 Project Server 2013,它成功检索了任务 (StatusAssignments),但在 self.Assignments.Update();self.Assignments.SubmitAllStatusUpdates("By PS Web App"); 之后,异常在 context.ExecuteQuery();.

上抛出

有人遇到过这样的场景吗?

我希望遇到同样问题的人不会迟到,这个问题已经解决并且工作正常,但我不确定这是否是正确的方法。

我没有通过当前用户上下文更新 TaskAssignment,而是使用提升的上下文(例如管理上下文)获取它,并获取资源的分配并更新它们。

//private function to get admin context
ProjectContext elevatedContext = GetProjectElevatedContext(connection);
//private function to get current user context
ProjectContext context = GetProjectContext(connection);

// Get the user name  and their assignments
EnterpriseResource self = EnterpriseResource.GetSelf(context);
context.Load(self, r => r.Id, r => r.Assignments.IncludeWithDefaultProperties(a => a.ActualFinish));
context.ExecuteQuery();

var resource = elevatedContext.EnterpriseResources.GetById(self.Id.ToString());
elevatedContext.Load(resource, r => r.Assignments
    .IncludeWithDefaultProperties(a => a.Project, a => a.Comments, a => a.PercentComplete));
elevatedContext.ExecuteQuery();

int count = 0;

foreach (var item in resource.Assignments)
{
    Entities.Task task = data.Where(t => t.ID == item.Id).SingleOrDefault();
    if (task != null)
    {
        item.PercentComplete = (short)task.PercentComplete;
        item.Comments = "comment";
        count++;
    }
}

resource.Assignments.Update();
resource.Assignments.SubmitAllStatusUpdates($"comment");
elevatedContext.ExecuteQuery();

我找不到 CSOM 为此类功能授予的权限。

如果有人有更好的测试解决方案,请贡献:)