Answered by:
How to Move a task using PSI?
Question

Hi,
I can not understand how to use the outline level (or any other solution) to move a task, using PSI.
I Have the following scenario:
Task Name Task 1 Task 1.1 Task 1.2 Task 1.3 Task 1.4 Task 2 Task 3 Task 3.1 Task 3.2 Task 3.3 Task 3.4 I need to move task 3.3 (Outline leve 2) to be sibiling of task 1.2, if I use the outline level, for example:
Guid movetaskUID = new Guid("cacaa05afb784ced862d2d9b282e754a"); ProjectDataSet.TaskRow movetask =( from task in projectDS.Task where task.RowState != System.Data.DataRowState.Deleted && task.TASK_UID == movetaskUID select task ).First(); movetask.TASK_OUTLINE_LEVEL = 1; //... update
I get the following result
Task Name Task 1 Task 1.1 Task 1.2 Task 1.3 Task 1.4 Task 2 Task 3 Task 3.1 Task 3.2 Task 3.3 Task 3.4 How can I use PSI to achieve the following result? Can anyone provide any documentation / blog /...?
Task Name Task 1 Task 1.1 Task 1.2 Task 3.3 Task 1.3 Task 1.4 Task 2 Task 3 Task 3.1 Task 3.2 Task 3.4 Thanks
Regards,
RicardoMonday, January 31, 2011 5:46 PM
Answers

Changing the TASK_OUTLINE_LEVEL to 1 is the same as selecting the green Outdent Task arrow in the Schedule group of the Task ribbon in Proj Pro. Also, you can't change the TASK_OUTLINE_NUM, because that is readonly, and internally changed when you reposition the task.
For example, use ProjPro to create a project with the tasks in the order you want, save and close it, and take a look at the project in ProjTool. Then edit the project in ProjPro, move the task where you want, save/close, and look at it again in ProjTool. Whereas in the first case, Task 3.3 was the ProjectDataSet.Task[10] row, after moving the task below 1.2, it becomes the ProjectDataSet.Task[4] row. Project Server has changed the TASK_ID and TASK_OUTLINE_NUM values internally, as well as the TASK_WBS values down the line.
So, you could try the ReadProject method to get the full ProjectDataSet, build a new ProjectDataSet rowbyrow from the old one, moving Task 3.3 from the 10th row to the 4th row, and then use the new ProjectDataSet with the QueueUpdateProject method. (I haven't done this  you might also need to change the TASK_WBS values in the new ProjectDataSet for all the rows after Task 1.2  they aren't readonly. But try it first without doing that, to see if Project Server does the job with TASK_WBS)
Jim
Jim Corbin [MSFT] Proposed as answer by Jim Corbin Tuesday, February 1, 2011 6:50 PM
 Marked as answer by Christophe FiessingerMicrosoft employee Tuesday, February 1, 2011 7:51 PM
Tuesday, February 1, 2011 12:15 AM
All replies

Changing the TASK_OUTLINE_LEVEL to 1 is the same as selecting the green Outdent Task arrow in the Schedule group of the Task ribbon in Proj Pro. Also, you can't change the TASK_OUTLINE_NUM, because that is readonly, and internally changed when you reposition the task.
For example, use ProjPro to create a project with the tasks in the order you want, save and close it, and take a look at the project in ProjTool. Then edit the project in ProjPro, move the task where you want, save/close, and look at it again in ProjTool. Whereas in the first case, Task 3.3 was the ProjectDataSet.Task[10] row, after moving the task below 1.2, it becomes the ProjectDataSet.Task[4] row. Project Server has changed the TASK_ID and TASK_OUTLINE_NUM values internally, as well as the TASK_WBS values down the line.
So, you could try the ReadProject method to get the full ProjectDataSet, build a new ProjectDataSet rowbyrow from the old one, moving Task 3.3 from the 10th row to the 4th row, and then use the new ProjectDataSet with the QueueUpdateProject method. (I haven't done this  you might also need to change the TASK_WBS values in the new ProjectDataSet for all the rows after Task 1.2  they aren't readonly. But try it first without doing that, to see if Project Server does the job with TASK_WBS)
Jim
Jim Corbin [MSFT] Proposed as answer by Jim Corbin Tuesday, February 1, 2011 6:50 PM
 Marked as answer by Christophe FiessingerMicrosoft employee Tuesday, February 1, 2011 7:51 PM
Tuesday, February 1, 2011 12:15 AM 
Hi Jim,
Thanks for your reply, I will try that solution. But, for example, the reported time (in timesheet) or other data associated with a specif Task ID will be lost?
Ricardo
Wednesday, February 2, 2011 11:11 AM 
Timesheet lines are associated with task and assignment GUIDs, not the relative task ID. But again, I haven't tried it. Think of this as an experiment.
Jim
Jim Corbin [MSFT]Wednesday, February 2, 2011 3:23 PM 
Timesheet lines are associated with task and assignment GUIDs, not the relative task ID. But again, I haven't tried it. Think of this as an experiment.
Jim
Jim Corbin [MSFT]
My guess is that creating a new project with tasks will create new guids. How about adding another field with the desired ID's, then sort by that field and permanently renumber? I don't think this is possible within the PSI though.
Jack Dahlgren blogs at:
Project and Retrovention
and rarely TwitterWednesday, February 2, 2011 4:36 PM 
Hi,
I were able to move a task, deleting and creating a new one using:
SvcProject.ProjectDataSet.TaskRow oldTask = projectDS.Task.FindByTASK_UIDPROJ_UID(new Guid("cacaa05afb784ced862d2d9b282e754a"),
projectGuid);
SvcProject.ProjectDataSet.TaskRow newTask = projectDS.Task.NewTaskRow();
newTask.ItemArray = oldTask.ItemArray;
newTask.AddPosition = 1;
newTask.PROJ_UID = projectGuid;
newTask.AddAfterTaskUID = new Guid("3a06b0924b344baa8473ebe1901457bd");
oldTask.Delete();
projectDS.Task.Rows.Add(newTask);but, even, if the TASK_UI is the same the timesheet and assigments are lost.
@Jack I understand that new field can be use to sort the task, but the TASK_PARENT_UID is not updated? Can y please detail a litle bit more your idea?
Using the PWA It's possible to copy and paste a task without losing the assigments and timesheet, so it should be possible to do the same using PSI?
Regards
Ricardo Rocha
Wednesday, February 2, 2011 5:32 PM 
When you create a task, you also must create a GUID  so the assignments and timesheet know nothing about the new task.
The algorithim I had in mind is to simply move the existing task to a different row in the ProjectDataSet.Task table, thereby keeping the original task GUID.
Jim
Jim Corbin [MSFT]Wednesday, February 2, 2011 6:04 PM