Project Server – Creating a Task Hierarchy using PSI

The following questions has been asked:

"[…] is there a way to set up the task hierarchy within a single project?"

and the answer is YES! To create a hierarchy within a single project, you have to set the outline level for the sub tasks. The below example creates two task, Summary Task and Sub Task. For the Summary Task, we do not set the outline level, we just create it as normal task. The Sub Task is where you set the outline level. In this example we set the outline level to 2:

Connection conn = new Connection("http://chboyd01/pwa");

WSProject.Project projWS = (WSProject.Project)conn.GetWebService(Connection.Project);

Guid sessGuid = Guid.NewGuid();
Guid jobGuid = Guid.NewGuid();
Guid taskGuid = Guid.NewGuid();

Guid projGuid = GetProjectUidFromProjectName("Excel");

projWS.CheckOutProject(projGuid, sessGuid, "");

WSProject.ProjectDataSet dsP;

// Create a task with a constraint

dsP = new WSProject.ProjectDataSet();

WSProject.ProjectDataSet.TaskRow taskRow = dsP.Task.NewTaskRow();

// Set the required fields

taskRow.PROJ_UID = projGuid;
taskRow.TASK_UID = taskGuid;
taskRow.TASK_NAME = "Summary Task";

taskRow.AddPosition = (int)PSLibrary.Task.AddPositionType.Last;

dsP.Task.AddTaskRow(taskRow);

projWS.QueueAddToProject(jobGuid, sessGuid, dsP, false);

// Create a second task

dsP = new WSProject.ProjectDataSet();

taskRow = dsP.Task.NewTaskRow();

Guid task2Guid = Guid.NewGuid();

jobGuid = Guid.NewGuid();

// Set the required fields

taskRow.PROJ_UID = projGuid;
taskRow.TASK_UID = task2Guid;
taskRow.TASK_NAME = "Sub Task";

// Set the start and finish dates

taskRow.TASK_START_DATE = new DateTime(2007, 01, 31);
taskRow.TASK_FINISH_DATE = new DateTime(2007, 02, 03);

taskRow.TASK_OUTLINE_LEVEL = 2;

taskRow.AddPosition = (int)PSLibrary.Task.AddPositionType.Last;

dsP.Task.AddTaskRow(taskRow);

projWS.QueueAddToProject(jobGuid, sessGuid, dsP, false);

PublishProject(projGuid);

The below screen shot is the result of running the above sample code:

Chris Boyd

Advertisements

One thought on “Project Server – Creating a Task Hierarchy using PSI

  1. avx April 19, 2011 / 8:08 am

    Hi,
    what if you have more than one summary task in a project and want to add a subtask to existing summary task?
    TASK_PARENT_UID seems to be read-only, but when I use AddAfterTaskUID and TASK_OUTLINE_LEVEL, I get an error TaskCannotCreateSubTasksUnderTasksWithAssignments (there are no any assignements for summary task apart from assignement to “unassigned resource”)…
    And – is taskRow.AddPosition really necessary?
    Thanks.

Comments are closed.