次の方法で共有


Project.CustomFields プロパティ

プロジェクトの設定の値を持つユーザー設定フィールドをプロジェクトのコレクションを取得します。

名前空間:  Microsoft.ProjectServer.Client
アセンブリ:  Microsoft.ProjectServer.Client (Microsoft.ProjectServer.Client.dll 内)

構文

'宣言
<RemoteAttribute> _
Public ReadOnly Property CustomFields As CustomFieldCollection
    Get
'使用
Dim instance As Project
Dim value As CustomFieldCollection

value = instance.CustomFields
[RemoteAttribute]
public CustomFieldCollection CustomFields { get; }

プロパティ値

型: Microsoft.ProjectServer.Client.CustomFieldCollection
CustomFieldオブジェクトのコレクションです。

注釈

CustomFieldsプロパティは、プロジェクトのユーザー設定フィールド、プロジェクトの設定値がないを含まれません。たとえば、プロジェクトにしれませんという名前のプロジェクト テキスト ユーザー設定フィールドの値が含まれていない場合は、そのプロジェクトのCustomFieldsコレクション内でそのユーザー設定フィールドは含まれません。

次のコード例では、各公開企業のプロジェクトのユーザー設定フィールドのコレクションを照会します。GUID と、プロジェクト、名前、および各カスタム フィールドの値の名前と、プロジェクト内の各カスタム フィールドの内部名は、キーと値のペアのキーとして示します。ユーザー設定フィールドの参照テーブルを使用する場合、 FieldValuesの項目に参照テーブルのエントリの内部名が含まれます。複数値テキスト型フィールドをユーザー設定フィールドには場合は、例では、プロジェクトのカスタム フィールドの参照テーブルの各エントリの内部の名前と値を示します。ユーザー設定フィールドの参照テーブルを使用しない場合は、値がユーザー設定フィールド値にします。

ユーザー設定のフィールドの内部名は「Custom_ [GUID]」、などのCustom_9d77d62aa92e4d40adc8446c90eb7456値を持つ文字列。ルックアップ テーブルのエントリの内部名は「Entry_ [GUID]」、などのEntry_4a2750309d91e21193f90021704e28a0値を持つ文字列。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ProjectServer.Client;

namespace GetProjectFieldValues
{
    class Program
    {
        private const string pwaPath = "https://ServerName/pwa";    // Change the path for Project Web App.

        // Set the Project Server client context.
        private static ProjectContext projContext;

        static void Main(string[] args)
        {
            projContext = new ProjectContext(pwaPath);

            // Get the list of published projects in Project Web App.
            projContext.Load(projContext.Projects);
            projContext.ExecuteQuery();

            Console.WriteLine("\t\tProject ID\t     :\tProject name");

            if (projContext.Projects.Count > 0)
            {
                for (int i = 0; i < projContext.Projects.Count; i++)
                {
                    var pubProj = projContext.Projects[i].IncludeCustomFields;
                    projContext.Load(pubProj);
                    projContext.Load(pubProj.CustomFields);
                    projContext.ExecuteQuery();

                    Console.WriteLine("\n{0} :\t{1}", pubProj.Id.ToString(), pubProj.Name);
                    int numCFs = pubProj.CustomFields.Count;
                    Console.WriteLine("Number of custom fields: {0}", numCFs.ToString());

                    Dictionary<string, object> projDict = pubProj.FieldValues;

                    // Variables to compare with custom field types:
                    string textValue = "";                  // TEXT - no lookup table
                    String[] lutTextValues = { "" };        // TEXT - lookup table
                    DateTime dateValue = DateTime.MinValue; // DATE - no lookup table

                    foreach (KeyValuePair<string, object> kvp in projDict)
                    {
                        object oVal = kvp.Value;
                        string keyStr = kvp.Key;

                        var projCFs = projContext.LoadQuery(pubProj.CustomFields
                            .Where(cf => cf.InternalName == keyStr));
                        projContext.ExecuteQuery();

                        Console.WriteLine("\n    Custom field: '{0}'; FieldType = {1};\n\tInternalName = {2}",
                            projCFs.First().Name, projCFs.First().FieldType.ToString(), keyStr);

                        // Check whether the custom field is a simple text field.
                        if (object.ReferenceEquals(oVal.GetType(), textValue.GetType()))
                        {
                            textValue = (string)oVal;
                            Console.WriteLine("\tSingle-line string value = {0}", textValue.ToString());
                        }
                        // Check whether the custom field is a text (or multivalue text) field from a lookup table.
                        else if (object.ReferenceEquals(oVal.GetType(), lutTextValues.GetType()))
                        {
                            projContext.Load(projCFs.First().LookupTable);
                            projContext.ExecuteQuery();
                            string lutName = projCFs.First().LookupTable.Name;

                            Console.WriteLine("\tLookup table: {0}", lutName);

                            var luts = projContext.LoadQuery(projContext.LookupTables
                                .Where(lut => lut.Name == lutName));
                            projContext.ExecuteQuery();

                            lutTextValues = (string[])oVal;

                            for (var j = 0; j < lutTextValues.Count(); j++)
                            {
                                var entries = projContext.LoadQuery(luts.First().Entries
                                    .Where(e => e.InternalName == lutTextValues[j]));
                                projContext.ExecuteQuery();
                                Console.WriteLine("\t    Entry({0}): String value = {1};\n\t\t  InternalName = {2}",
                                    j, entries.First().FullValue, lutTextValues[j]);
                            }
                        }
                        // Check whether the custom field is a date.
                        else if (object.ReferenceEquals(oVal.GetType(), dateValue.GetType()))
                        {
                            dateValue = (DateTime)oVal;

                            Console.WriteLine("\tDate value = {0}", dateValue.ToString());
                        }
                        // Add other cases for cost, duration, flag, and number custom fields,
                        // with and without lookup tables.
                    }
                }
            }
            Console.Write("\nPress any key to exit: ");
            Console.ReadKey(false);
        }
    }
}

たとえば、TestProject9 という名前のプロジェクトが、プロジェクトの部署ユーザー設定フィールドの値を複数値テキスト ユーザー設定フィールド参照テーブルのエントリの 3 つの値、単純なテキストのユーザー設定フィールドおよびユーザー設定の日付フィールドです。プロジェクトの部門は、組み込みのユーザー設定フィールド、プロジェクトの部署ユーザー設定フィールドの GUID を既定のためのProject Web Appのインスタンスは9d77d62a-a92e-4d40-adc8-446c90eb7456です。GetProjectFieldValuesサンプル アプリケーションの出力を次に示します。

b846e947-29e0-43eb-b5c6-5ddeaf08d5c0 :  TestProject9
Number of custom fields: 4

    Custom field: 'Project Departments'; FieldType = TEXT;
        InternalName = Custom_9d77d62aa92e4d40adc8446c90eb7456
        Lookup table: Department
            Entry(0): String value = Test Dept 1;
                  InternalName = Entry_bbc07ff5b06de21193f40021704e28a0

    Custom field: 'ProjectMVText'; FieldType = TEXT;
        InternalName = Custom_9295a8759d91e21193f90021704e28a0
        Lookup table: TestTextMV
            Entry(0): String value = First.001;
                  InternalName = Entry_4a2750309d91e21193f90021704e28a0
            Entry(1): String value = Second.002;
                  InternalName = Entry_4d2750309d91e21193f90021704e28a0
            Entry(2): String value = Third;
                  InternalName = Entry_4f2750309d91e21193f90021704e28a0

    Custom field: 'Test Project Date'; FieldType = DATE;
        InternalName = Custom_37f61601a991e21193f90021704e28a0
        Date value = 3/29/2013 8:00:00 AM

    Custom field: 'Test project simple text'; FieldType = TEXT;
        InternalName = Custom_8bf7eed5cc94e21193f90021704e28a0
        Single-line string value = This is a line of text

関連項目

参照先

Project クラス

Project メンバー

Microsoft.ProjectServer.Client 名前空間