Creating a Task Hierarchy


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


 


Technorati tags: , , ,

Comments (2)

  1. Jan Schaumann says:

    Hi,

    Could you show me how to do with UpdateTask not with CreateTask?

    Thank you

    Jan Schaumann

    schaumann.jan@gmail.com

  2. vendre says:

    Have to set the position type to:

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

    otherwise don't working