Set task custom field value for first time with CSOM RRS feed

  • Question

  • I have developed in C# a console application which updates task custom fields by using CSOM on a Project Online environment. Code snippet:

         string cInternalNameOriginalEstimate = cProjectContext.CustomFields.First(cf => string.Equals(cf.Name, Settings.Default.OriginalEstimateField, StringComparison.OrdinalIgnoreCase)).InternalName;
         PublishedProject lProject = cProjectContext.Projects.GetByGuid(projectUID);
         cProjectContext.Load(lProject, p => p.IsCheckedOut, p => p.Name);
         if (!lProject.IsCheckedOut)
            DraftProject lDraftProject = lProject.CheckOut();
            cProjectContext.Load(lDraftProject, p => p, p => p.Tasks);            
            foreach (var iTask in lDraftProject.Tasks)
               //Select task 
               lDraftTask = iTask;
               lDraftTask[cInternalNameOriginalEstimate] = iUpdateTask.originalEstimate;
               QueueJob lUpdateJob = lDraftProject.Update();
               JobState lUpdateState = cProjectContext.WaitForQueue(lUpdateJob, Settings.Default.PublishTimeout);
               if (lUpdateState != JobState.Success)
                  cLog.AppendLine("WARNING: Updating tasks and assignments queue job not succesful after waiting for " + Settings.Default.PublishTimeout + " seconds. Check Project Online queue.");
               bool lPublishError = false;
                  cLog.AppendLine("Publish project");
                  QueueJob lPublishJob = lDraftProject.Publish(false);
                  JobState lState = cProjectContext.WaitForQueue(lPublishJob, Settings.Default.PublishTimeout);
                  if (lState != JobState.Success)
                     cLog.AppendLine("WARNING: Publish queue job not succesful after waiting for " + Settings.Default.PublishTimeout + " seconds. Check Project Online queue.");
                  lPublishError = true;

    This code works perfectly when updating the task custom field. But setting the task custom field for the first time, throws an error when checking the state of the publish job:

    ERROR while publishing project: PJClientCallableException: GeneralQueueCorrelationBlocked GeneralQueueCorrelationBlocked CorrelationUID = 627d3c25-2a29-e811-80d9-00155db8792b JobUID = 26346e5b-0031-e911-afac-00155d243a10 JobType = ProjectPublish

    Checking the Project Online queue reveals that it was the Project Update from PSI queue job that has an error which causes the Publish job to be blocked. The error of the Update job is the following:

    ProjectDataSet Table TaskCustomFields Row: CUSTOM_FIELD_UID='98480855-0031-e911-afac-00155d243a10' Error CustomFieldRowAlreadyExists (11708) - column

    Some remarks:
    The UID that is shown here does not exist in the custom fields
    When looking at the lDrafTask object, the custom field I am trying to set is missing from FieldValues and CustomFields properties (probably because no value was set yet)

    The weird thing is, the update job actually works. The task custom field value is correctly set. But because the Publish job fails, the custom field value is not pushed to the Published store.

    I've also tried to set an assignment custom field and it is the same issue there: works for an update but not for setting the value for the first time. The error message of the Update job is slightly different:

    ProjectDataSet Table AssignmentCustomFields Row: CUSTOM_FIELD_UID='c140bd41-f530-e911-afaa-00155d248209' Error CustomFieldInvalidID (11701) - column

    Same situation here: custom fields UID shown here does not exist.

    So I guess someting internally goes wrong when setting a task or assignment custom field for the first time.

    Has anyone else encountered this issue? Is there a workaround?

    Monday, February 18, 2019 1:40 PM