none
How to update an Enterprise Custom Field with a lookup table value using PSI? RRS feed

  • Question

  • Hi All,

    I'm trying to use PSI to modify a project-level ECF value with a corresponding lookup table. I am able to read the CODE_VALUE and using LookupTableTreesRow, I can get the corresponding LT_VALUE_FULL of the CODE_VALUE. My question is how can I update the CODE_VALUE so that in my project properties window, I can see the new ECF value. In my queue I can see the "Project Update from PSI" job that is successful but when I look at my project, the value is not changed. Below is my code. I'm not sure if I did it correctly or if I am missing any step:

     

    Guid projectGuid;

    Guid codeValue = new Guid();

     

    string divName = String.Empty;

    WebSvcProject.

    ProjectDataSet projectDs = project.ReadProjectList();

     

    foreach (WebSvcProject.ProjectDataSet.ProjectRow projectRow in projectDs.Project)

    {

     

    if (projectRow.PROJ_NAME.ToUpper() == "zzzz_NoynoyTest_ModifyDivision".ToUpper())

    {

    projectGuid = projectRow.PROJ_UID;

     

    Guid sessionUid = Guid.NewGuid();

    project.CheckOutProject(projectGuid, sessionUid,

    "Updating Division");
     

    WebSvcProject.

    ProjectDataSet dsProject = new WebSvcProject.ProjectDataSet();

    dsProject = project.ReadProject(projectGuid, WebSvcProject.

    DataStoreEnum.WorkingStore);

     

    foreach (WebSvcProject.ProjectDataSet.ProjectCustomFieldsRow rowProjectCF in dsProject.ProjectCustomFields)

    {

     

    if (rowProjectCF.MD_PROP_UID == divisionCFGuid)

    {

    codeValue = rowProjectCF.CODE_VALUE;

     

     

    // Using the Guid for the lookup table we search for the code value

     

    Guid[] ltUidList = new Guid[] { divisionLUTGuid };

    WebSvcLookupTable.

    LookupTableDataSet dsLookupTable = new WebSvcLookupTable.LookupTableDataSet();

    dsLookupTable = lookupTable.ReadLookupTablesByUids(ltUidList,

    false, 1033);

     

    foreach (WebSvcLookupTable.LookupTableDataSet.LookupTableTreesRow rowLookupTable in dsLookupTable.LookupTableTrees)

    {

     

    if (rowLookupTable.LT_STRUCT_UID == codeValue)

    {

    divName = rowLookupTable.LT_VALUE_FULL;

     

    MessageBox.Show(String.Format("Division for Project {0} is {1}", projectRow.PROJ_NAME, divName));

     

    break;

    }

    }

     

    //change the CODE_VALUE to 0011C324-6697-4958-A55F-5A3FB0A705C6

    rowProjectCF.CODE_VALUE =

    new Guid("F43AD950-90FD-45CD-9FB1-994D5260832B");

    rowProjectCF.AcceptChanges();

    dsProject.AcceptChanges();

     

    Guid jobUid = Guid.NewGuid();

    project.QueueUpdateProject(jobUid, sessionUid, dsProject,

    false);

    WaitForQueue(queue, jobUid);

    jobUid =

    Guid.NewGuid();

    project.QueueCheckInProject(jobUid, projectGuid,

    false, sessionUid, "Updating Division");

    codeValue = rowProjectCF.CODE_VALUE;

     

    foreach (WebSvcLookupTable.LookupTableDataSet.LookupTableTreesRow rowLookupTable in dsLookupTable.LookupTableTrees)

    {

     

    if (rowLookupTable.LT_STRUCT_UID == codeValue)

    {

    divName = rowLookupTable.LT_VALUE_FULL;

     

    MessageBox.Show(String.Format("Division for Project {0} is {1}", projectRow.PROJ_NAME, divName));

     

    break;

    }

    }

     

    break;

    }

    }

    }

    }

    Thanks in advance,

    Noynoy 

    Monday, May 23, 2011 2:59 AM

All replies