[英]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.