【问题标题】:Unable to update CustomField on a Task or Project with Lookup table GUID using csom无法使用 csom 更新具有查找表 GUID 的任务或项目的 CustomField
【发布时间】:2016-09-20 21:46:23
【问题描述】:

是否有人设法在使用查找值的任务或项目上以编程方式更新自定义字段?我正在使用 CSOM,代码如下,c#。查找自定义字段会更新,但字段设置为空白,覆盖使用 Web 应用输入的先前值。对“文本”自定义字段的更新工作正常。

private void SendCode()
{
    ProjectContext context;
    using (context = new ProjectContext(ConfigurationManager.AppSettings["psUrl"]))
    {
        context.Load(context.Projects,
            pj => pj.Include(
                p => p.Id,
                p => p.Name));
        context.Load(context.CustomFields,
            lts => lts.Include(
                lt => lt.Name,
                lt => lt.InternalName));

        context.ExecuteQuery();
        // Output Status is a Custom Filed referring to a lookup table called Output Status with 6 status values
        string customFieldName = "Output Status";
        // A routine to get the correct GUID from the lookup Table
        object customFieldValue = new Guid("1aded2bc-67ad-49e4-9c52-a9dca4ea09a5");
        foreach (PublishedProject pp in context.Projects)
        {
            DraftProject proj2Edit = pp.CheckOut().IncludeCustomFields;
            context.Load(proj2Edit.Tasks,
                ts => ts.Include(
                    t => t.Id,
                    t => t.Name,
                    t => t.CustomFields,
                    t => t.OutlineLevel,
                    t => t.IsSummary));
            context.ExecuteQuery();
            var cfInternalName = context.CustomFields.First(cf => cf.Name == customFieldName).InternalName;
            DraftTask newTask = proj2Edit.Tasks.First(t => t.Name == "REI and PPR Monitoring");
            newTask[cfInternalName] = customFieldValue;  // How should you be setting the GUID?
            proj2Edit.Publish(true);
            QueueJob qJob = context.Projects.Update();
            JobState jobState = context.WaitForQueue(qJob, QueueTimeout);
        }
    }
}

【问题讨论】:

    标签: c# csom psi


    【解决方案1】:
    猜你喜欢
    • 2016-04-18
    • 2016-02-18
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多