2

私は Project Server の開発にかなり慣れていないので、1 回のパスで複数のカスタム フィールドを更新する必要がある次のコードをどのように変更する必要があるのか​​疑問に思っていました。複数のカスタム フィールドの更新を開始したい時点まで、すべてが機能しています。多数のチュートリアルを実行しましたが、この問題に有効な解決策が見つかりませんでした。私がまとめた現在のプログラムは、最初の ForEach cfValueWOD カスタム フィールドを更新するだけです。複数のフィールドに既に値がある場合はコードを更新できますが、私のプロジェクトでは、これらのカスタム フィールドに初期値があるか、開始する値がない可能性があります。どちらの場合も、これらのフィールドに値を書き込む必要があります。仕事中のプロジェクトのためにこれをすぐに完了する必要があり、途方に暮れています。あなたの助けは大歓迎です。私の現在のコードは次のとおりです。

{
    static void WriteCustomFields()
    {
        //Guids for custom fields to update - Test
        string cfNameWOD = "WO Description"; //Test WO Description custom field
        string cfValueWOD = "xxxx5WODes";
        Guid cfIdWOD = new Guid("{8071365c-1375-46a1-9424-cd79f3c2b0db}");

        string cfNameWG = "Work Group"; //Test Work Group custom field
        string cfValueWG = "xxxx5Group";
        Guid cfIdWG = new Guid("{f75c6cfb-b7cb-4d35-8b04-60efb12fcd39}");                

        //projects into a dataset
        ProjectDataSet projectList = projectSvc.ReadProjectList();

        //read project data
        Guid myProjectUid = new Guid("{c96bd7ea-e9d2-47ed-8819-02e4653e92a7}");
        ProjectDataSet myProject = projectSvc.ReadProject(myProjectUid, DataStoreEnum.WorkingStore);

        //indicate the custom field has been found
       bool customFieldFound = false;

        //iterate over fields and update them to the table for WO Status
        foreach (ProjectDataSet.ProjectCustomFieldsRow cfRow in myProject.ProjectCustomFields)
        {
            //if field exists update it
            if (cfRow.MD_PROP_UID == cfIdWOD)
            {
                //update the value
                cfRow.TEXT_VALUE = cfValueWOD;
                customFieldFound = true;
            }

        }
        //check if the custom field has been found
        if (!customFieldFound)
        {
            //create a new row
            ProjectDataSet.ProjectCustomFieldsRow cfRowWOD =
                myProject.ProjectCustomFields.NewProjectCustomFieldsRow();

            //Sets all values to NUll to begin
            cfRowWOD.SetDATE_VALUENull();
            cfRowWOD.SetTEXT_VALUENull();

            //General parameters
            cfRowWOD.MD_PROP_UID = cfIdWOD; //custom field ID
            cfRowWOD.CUSTOM_FIELD_UID = Guid.NewGuid();
            cfRowWOD.PROJ_UID = myProjectUid; //current project ID

            //add value
            cfRowWOD.FIELD_TYPE_ENUM = 21;
            cfRowWOD.TEXT_VALUE = Convert.ToString(cfValueWOD); //test value

            //add the row to the data set
            myProject.ProjectCustomFields.AddProjectCustomFieldsRow(cfRowWOD);
        }

        //iterate over fields and update them to the table for WO Status
        foreach (ProjectDataSet.ProjectCustomFieldsRow cfRow in myProject.ProjectCustomFields)
        {
            //if field exists update it
            if (cfRow.MD_PROP_UID == cfIdWG)
            {
                //update the value
                cfRow.TEXT_VALUE = cfValueWG;
                customFieldFound = true;
            }

        }
        //check if the custom field has been found
        if (!customFieldFound)
        {
            //create a new row
            ProjectDataSet.ProjectCustomFieldsRow cfRowWG =
                myProject.ProjectCustomFields.NewProjectCustomFieldsRow();

            //Sets all values to NUll to begin
            cfRowWG.SetDATE_VALUENull();
            cfRowWG.SetTEXT_VALUENull();

            //General parameters
            cfRowWG.MD_PROP_UID = cfIdWG; //custom field ID
            cfRowWG.CUSTOM_FIELD_UID = Guid.NewGuid();
            cfRowWG.PROJ_UID = myProjectUid; //current project ID

            //add value
            cfRowWG.FIELD_TYPE_ENUM = 21;
            cfRowWG.TEXT_VALUE = Convert.ToString(cfValueWG); //test value

            //add the row to the data set
            myProject.ProjectCustomFields.AddProjectCustomFieldsRow(cfRowWG);
        }

        //generate sessionId for tracking
        Guid sessionId = Guid.NewGuid(); //sessionId for updating process
        Guid jobId = Guid.NewGuid(); //ID for each job

        //check out project
        projectSvc.CheckOutProject(myProjectUid, sessionId,
            "update checkout");

        //update project database
        bool validateOnly = false;
        projectSvc.QueueUpdateProject(jobId, sessionId,
            myProject, validateOnly);

        //wait to finish
        WaitForJob(jobId);

        //new jobId to check in the project
        jobId = Guid.NewGuid();

        //check in the updated project
        bool force = false;
        string sessionDescription = "update custom fields";
        projectSvc.QueueCheckInProject(jobId, myProjectUid,
            force, sessionId, sessionDescription);

        //wait to finish
        WaitForJob(jobId);

        //new jobId to publish the project
        jobId = Guid.NewGuid();
        bool fullPublish = true;
        projectSvc.QueuePublish(jobId, myProjectUid, fullPublish, null);

        //wait to finish
        WaitForJob(jobId);

    }
4

1 に答える 1