none
Question on PSI: Setting Constraint Type RRS feed

  • Question

  •  

    In our current project, we are using the PSI to copy multiple tasks from one section of the project and paste at the end in order to create new set of tasks within the project. Below is the code snippet from our solution. We, first, create a new task object. And then we unto newly created blank task, we copy the task from the source task (from another section of the project). Then, we assign new task ID GUID. Everything gets copied correctly when comparing the original task and newly created task. One property we have question is Task_Contraint_Type. The source task’s Task_Contraint_Type is “As soon as possible” and when we make the copy (as in the code below and upon saving the project data back to Project Server and publish/check-in the project, when we open the project, the newly created task’s constraint type is “This task has a ‘Start No Earlier Than’ constraint on Date” (See image below). We expected “As soon as possible” because the source task was “As soon as possible” However, this was not the case.

    As a result, we modified the code (see bold) so that during the copy/create new task, we set Task_Constaint_Type to “As soon as possible”. However, this still resulted, again, in “This task has a ‘Start No Earlier’…” constraint. The workaround for now was after we finish copy all tasks, we then grab the dataset again and then update all tasks once again to set the Task_Constraint_Type to “As soon as possible”. However, this results in doing the work twice and can be potential performance hit as we noticed that calling “QueueAddToProject” took a lot of time as project gets fairly large (we create project of size 25k tasks). Do you know why setting Task_Constaint_Type  duing the initial task creation yields different value?

    // Create a new task object
    Project.ProjectDataSet.TaskRow newTask = _tasksDataset.Task.NewTaskRow();

    // Copy data from the source task to newly created task
    newTask.ItemArray = _tasksDataset.Task[i].ItemArray.Clone() as object[];

    // Make a new GUID to be the new task's GUID
    Guid taskId = Guid.NewGuid();

    // Assign differentiating properties to the new task
    newTask.PROJ_UID = _projectUid;
    newTask.TASK_UID = taskId;
    newTask.TASK_DUR = (int)PSLibrary.Task.DurationFormat.Day;
    newTask.TASK_CONSTRAINT_TYPE = 0;                                 // 0 = As soon as possible
    newTask.StatusManager = _projectOwnerUid;

    Monday, March 10, 2014 5:45 PM

Answers

  • Hi all,

    It turns out that calling:

    newTask.SetTASK_START_DATENull()
    newTask.SetTASK_FINISH_DATENull() 

    and then:

    newTask.TASK_CONSTRAINT_TYPE = 0;

     

    solves the problem of the constraint not being set.

    • Marked as answer by Mkleecmu Tuesday, March 18, 2014 2:14 PM
    Tuesday, March 18, 2014 2:14 PM