如何使用PSI设置多个自定义字段? - Microsoft Project Server [英] How can I set multiple custom fields with PSI? - Microsoft Project Server
问题描述
需要对以下代码进行哪些修改才能让它在一次传递中更新多个自定义字段。我已经开始工作,直到我想要开始更新多个自定义字段。我放在一起的当前程序只会导致更新第一个ForEach cfValueWOD自定义字段。我可以获得更新多个字段的代码,如果它们已经有值但是对于我的项目,这些自定义字段可以具有初始值或没有值来启动。在这两种情况下,我都需要为这些字段写入值。我需要很快完成这项工作,我很茫然。非常感谢您的帮助。我目前的代码片段如下:
What modifications need to be made the following code to have it update multiple Custom Fields in one pass. I have everything working up until the point I want to start updating multiple Custom Fields. The current program I’ve put together only results in updating the first ForEach cfValueWOD Custom Field. I can get the code to update multiple fields if they already have a value but for my project these custom fields can either have an initial value or no value to start. In both cases I will need to write values to these fields. I need to complete this for a project at work very soon and I’m at a loss. Your help will be much appreciated. My current code snipit is as follows:
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);
}
推荐答案
对于任何可能想知道如何做到这一点的人,我能够解决我的问题执行以下操作并将此部分重复到我需要更新的各个字段:
For anyone that may wonder how to do this I was able to solve my problem by doing the following and just repeating this section to various fields I need to update:
{
//indicate the custom field has been found
bool customFieldFound = false;
//iterate over fields and update them to the table for Current Proj Mgr
foreach (ProjectDataSet.ProjectCustomFieldsRow cfRow in myProject.ProjectCustomFields)
{
//if field exists update it
if (cfRow.MD_PROP_UID == cfIdPmID)
{
//update the value
cfRow.TEXT_VALUE = cfValuePmID;
customFieldFound = true;
}
}
//check if the custom field has been found
if (!customFieldFound)
{
//create a new row
ProjectDataSet.ProjectCustomFieldsRow cfRowPmID =
myProject.ProjectCustomFields.NewProjectCustomFieldsRow();
//Sets all values to NUll to begin
cfRowPmID.SetDATE_VALUENull();
cfRowPmID.SetTEXT_VALUENull();
//General parameters
cfRowPmID.MD_PROP_UID = cfIdPmID; //custom field ID
cfRowPmID.CUSTOM_FIELD_UID = Guid.NewGuid();
cfRowPmID.PROJ_UID = myProjectUid; //current project ID
//add value
cfRowPmID.FIELD_TYPE_ENUM = 21;
cfRowPmID.TEXT_VALUE = Convert.ToString(cfValuePmID);
//add the row to the data set
myProject.ProjectCustomFields.AddProjectCustomFieldsRow(cfRowPmID);
}
}
I moved the
'bool customFieldFound = false;'
to inside each update/create logic above the
'foreach (ProjectDataSet.ProjectCustomFieldsRow cfRow in myProject.ProjectCustomFields)'
这篇关于如何使用PSI设置多个自定义字段? - Microsoft Project Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!