4

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);
        }
Bargant
  • 260
  • 1
  • 2
  • 13
  • 1
    Have you published your project after the add-process? – cansik May 21 '12 at 09:27
  • 1
    Yes, I have. I've added check-out, check-in and publish to the code above. – Bargant May 21 '12 at 10:12
  • 1
    The only different thing I'm doing is to `QueueUpdateProject`the project instead of `QueueAddToProject`. – cansik May 21 '12 at 11:15
  • When I run it with QueueUpdateProject, it raises an exception: System.Web.Services.Protocols.SoapException: ProjectServerError(s) LastError=GeneralOnlyUpdatesAllowed Instructions – Bargant May 21 '12 at 13:42

1 Answers1

3

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.

Kit Menke
  • 7,046
  • 1
  • 32
  • 54
  • Hi Kit, I agree PSI is extremly complicated... I have tried Project.ReadProjectEntities and dsProject.GetChanges() QueueUpdateProject is still raising an exception while QueueAddToProject is behaving the same way... Do you have any other idea? Thanks. – Bargant May 22 '12 at 09:43
  • Is it still raising the GeneralOnlyUpdatesAllowed exception when using QueueUpdateProject? Also, only some of your fields are working? Does it work when you only use SetNumberCustomField ? – Kit Menke May 22 '12 at 14:56
  • Yes, the GeneralOnlyUpdatesAllowed exception is raised using QueueUpdateProject. There are 2 number custom fields working (the ones that existed before I started the project) and 1 number field not working, as same as 2 date fields and one text field. All the non working fields where created for this project. In resume, SetNumberCustomField works for the old fields but not for the new one. – Bargant May 23 '12 at 09:22