PSI new task custom fields are not being written

1.2k views Asked by At

I am developing a process throught PSI that adds a new task into a existing project. For this purpose, first, via PWA, I have created 4 new task custom fields (one numeric, two dates and one text) I need to inform when I create the task. I also have to write 2 numeric task custom fields that already existed.

The task is being created correctly and the two custom fields that existed before are also being written correctly. But, any of the new 4 new custom fields are being written. How can I solve this?

This is the code:

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 (I omitted data and text functions because essentially are the same)

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);
        }
1

There are 1 answers

3
Kit Menke On

I notice a couple issues with your code. The PSI is extremely complicated so I don't make an guarantees.. but here goes. :)

1) Your ProjectDataSet is not being initialized correctly.

You'll need to use Project.ReadProjectEntities to get an initial ProjectDataSet to work with. You will want to use the logical OR (|) to get multiple tables. You'll need Project | TaskCustomFields.

I'm pretty sure you'll need to do this if you are making updates.

2) Commit the changes

Before you commit, you can get only the changes from the ProjectDataSet.

ProjectDataSet updates = dsProject.GetChanges() as ProjectDataSet;

Then, you can call QueueUpdateProject and pass it only the updates dataset. Then, go ahead and QueuePublish.