[英]How to get Value of a custom field task in CSOM Project Server
我正在为项目服务器开发控制台应用程序。 Atm我可以读取项目中每个任务的名称和工作百分比。 每个任务都有一个具有唯一ID的自定义字段。 看起来像这样。
如何获得唯一ID的值? 例如84
这是我列出任务名称和工作百分比的代码:
var projColl = projContext.LoadQuery(projContext.Projects
.Where(p => p.Name == projectName)
.Include(
p => p.Name,
p => p.Tasks,
p => p.Tasks.Include(
t => t.Name,
t => t.PercentComplete,
t => t.CustomFields
)
)
);
projContext.ExecuteQuery();
PublishedProject theProj = projColl.First();
PublishedTaskCollection taskColl = theProj.Tasks;
PublishedTask theTask = taskColl.First();
CustomFieldCollection LCFColl = theTask.CustomFields;
Dictionary<string, object> taskCF_Dict = theTask.FieldValues;
int k = 1; //Task counter.
foreach (PublishedTask t in taskColl)
{
Console.WriteLine("\t{0}. {1, -15} {2,-30}{3}", k++, t.Name, t.PercentComplete);
}
我尝试使用Console.WriteLine("\\t{0}. {1, -15} {2,-30}{3}", k++, t.Name, t.PercentComplete,t.CustomFields);
但我只会
Microsoft.ProjectServer.Client.CustomFieldCollection
我也知道customfield的InternalName是否有帮助
编辑:我添加了这个exsample,但我只得到第一行的值。 任何想法如何循环每一行?
因为你只得到从第一行的值LCFColl
被定义为对象变量的自定义字段theTask
不是变量t
您在循环中使用。 将LCFColl
的声明LCFColl
任务循环中:
foreach (PublishedTask t in taskColl)
{
CustomFieldCollection LCFColl = t.CustomFields;
foreach (CustomField cf in LCFColl)
{
// do something with the custom fields
}
Console.WriteLine("\t{0}. {1, -15} {2,-30}{3}", k++, t.Name, t.PercentComplete);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.