如何在CSOM Project Server中获取自定义字段任务的值

问题描述 投票:1回答:1

我正在为项目服务器的控制台应用程序工作。 Atm我可以读取项目中每个任务的名称和工作百分比。每个任务都有一个具有唯一ID的自定义字段。 It looks like this.

如何获取唯一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

如果有帮助,我也知道自定义字段的InternalName

编辑:我添加了this exsample但我只得到第一行的值。知道如何循环每一行吗?

c# csom ms-project project-server
1个回答
0
投票

您只从第一行获取值,因为LCFColl被定义为对象变量theTask的自定义字段,而不是您在循环中使用的变量t。在任务循环中移动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);

   }
© www.soinside.com 2019 - 2024. All rights reserved.