[英]Unable to update CustomField on a Task or Project with Lookup table GUID using csom
Has someone managed to update custom fields programmatically on a Task or a Project which uses lookup values? 有人设法在使用查找值的任务或项目上以编程方式更新自定义字段吗? I'm using CSOM, code is below, c#.
我正在使用CSOM,代码在下面,c#。 Lookup Custom Field does update but field set to blank, overwriting previous value entered using Web App.
查找自定义字段确实更新但字段设置为空白,覆盖使用Web App输入的先前值。 Updates to 'Text' Custom fields work fine.
“文本”自定义字段的更新工作正常。
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);
}
}
}
Found a solution. 找到了解决方案。 You do not pass the lookup GUID but the Intername of the LookupEntry as well.
您不会传递查找GUID,也可以传递LookupEntry的Intername。 The value should be something like 'Entry_...'
值应该是'Entry _...'
These posts were very helpful: https://social.msdn.microsoft.com/Forums/en-US/c91644b7-3c0f-4d65-a8d7-2dec128d1dcf/project-lookup-custom-field-update-with-csom?forum=project2010custprog 这些帖子非常有用: https : //social.msdn.microsoft.com/Forums/en-US/c91644b7-3c0f-4d65-a8d7-2dec128d1dcf/project-lookup-custom-field-update-with-csom?forum= project2010custprog
https://social.msdn.microsoft.com/Forums/en-US/b4d3ee63-965b-4489-8b34-6ad53b128553/csom-update-custom-field-based-on-lookup-table?forum=project2010custprog https://social.msdn.microsoft.com/Forums/en-US/b4d3ee63-965b-4489-8b34-6ad53b128553/csom-update-custom-field-based-on-lookup-table?forum=project2010custprog
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.