我正在通过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);
}
答案 0 :(得分:3)
我注意到您的代码存在一些问题。 PSI非常复杂,所以我不做出保证......但是这里有。 :)
1)您的ProjectDataSet未正确初始化。
您需要使用Project.ReadProjectEntities来获取初始的ProjectDataSet。您将需要使用逻辑OR(|
)来获取多个表。您需要Project | TaskCustomFields
。
如果您要进行更新,我很确定您需要这样做。
2)提交更改
在提交之前,您只能从ProjectDataSet中获取更改。
ProjectDataSet updates = dsProject.GetChanges() as ProjectDataSet;
然后,您可以调用QueueUpdateProject并仅传递更新数据集。然后,继续和QueuePublish。