我正在通过 PSI 开发一个流程,将新任务添加到现有项目中。为此,首先,通过 PWA,我创建了 4 个新的任务自定义字段(一个数字、两个日期和一个文本),我需要在创建任务时通知我。我还必须编写 2 个已经存在的数字任务自定义字段。
任务正在正确创建,并且之前存在的两个自定义字段也被正确写入。但是,正在编写新的 4 个新自定义字段中的任何一个。我该如何解决这个问题?
这是代码:
WSProject.Project project = InitProject();
project.CheckOutProject(projectGuid, sessionId, "Check out");
WSProject.ProjectDataSet dsProject = new WSProject.ProjectDataSet();
Guid taskGuid = CreateTaskRow(dsProject, projectGuid, taskname, duration, startdate);
Guid assignmentGuid = CreateAssignmentRow(dsProject, projectGuid, taskGuid, resGuid);
//Custom Fields
Guid idNCF1 = GetGuidUsingFieldName("NCF1"); //OLD
Guid idNCF2 = GetGuidUsingFieldName("NCF2"); //OLD
Guid idNCF3 = GetGuidUsingFieldName("NCF3"); //NEW
Guid idDCF1 = GetGuidUsingFieldName("DCF1"); //NEW
Guid idDCF2 = GetGuidUsingFieldName("DCF2"); //NEW
Guid idTCF1 = GetGuidUsingFieldName("TCF1"); //NEW
SetNumberCustomField(dsProject, projectGuid, taskGuid, idNCF3, 4); //Not Works
SetDateCustomField(dsProject, projectGuid, taskGuid, idDCF1, DateTime.Today); //Not Works
SetTextCustomField(dsProject, projectGuid, taskGuid, idTCF1, "A"); //Not Works
SetDateCustomField(dsProject, projectGuid, taskGuid, idDCF2, DateTime.Today); //Not Works
SetNumberCustomField(dsProject, projectGuid, taskGuid, idNCF1, 1); //Works
SetNumberCustomField(dsProject, projectGuid, taskGuid, idNCF2, 2); //Works
//Using debug, here I can see that all custom fields are properly set in dsProject TaskCustomFields table
Guid jobId = Guid.NewGuid();
project.QueueAddToProject(jobId, sessionId, dsProject, false);
WaitForQueue(jobId);
jobGuid = Guid.NewGuid();
project.QueueCheckInProject(jobGuid, projectGuid, true, sessionId, "Checked in");
jobGuid = Guid.NewGuid();
project.QueuePublish(jobGuid, projectGuid, true, "");
WaitForQueue(jobGuid);
SetNumberCustomField(我省略了数据和文本函数,因为本质上是相同的)
private static void SetNumberCustomField(WSProject.ProjectDataSet dsProject,
Guid projectId,
Guid taskId,
Guid customFieldId,
int CFValue)
{
WSProject.ProjectDataSet.TaskCustomFieldsRow tCustomField = dsProject.TaskCustomFields.NewTaskCustomFieldsRow();
tCustomField.CUSTOM_FIELD_UID = Guid.NewGuid();
tCustomField.PROJ_UID = projectId;
tCustomField.TASK_UID = taskId;
tCustomField.FIELD_TYPE_ENUM = (byte)PSLibrary.CustomField.Type.NUMBER;
tCustomField.NUM_VALUE = CFValue;
tCustomField.MD_PROP_UID = customFieldId;
dsProject.TaskCustomFields.AddTaskCustomFieldsRow(tCustomField);
}