Split Tasks
Sometimes it is not possible to complete a task as scheduled and it needs to be split into two or more parts. Aspose.Tasks support this Microsoft Project feature.
Splitting Tasks
The SplitParts property exposed by the Task class is used to determine the split parts of a task whereas the SplitTask method exposed by the ResourceAssignment class is used to split a single task into multiple parts. SplitParts returns a collection of split parts whereas the SplitTask method accepts start date, finish date and calendar arguments to split the task.
Splitting and Viewing Tasks in Microsoft Project
To split a task in Microsoft Project:
- Identify a long task and you want to divide.
- On the Task menu, select the Schedule group and click Split Task.
- Click at the position you want to split the task.
To see split tasks in Microsoft Project one can select Gantt Chart on the View menu. Split tasks are linked by a dotted line.
Split tasks in Microsoft Project
Creating and Splitting Task
To create and split a task, follow these steps:
- Create a new project.
- Create and assign a new calendar to the project.
- Create and add a new task in the project.
- Create and add a new resource assignment in the project.
- Use the SplitTask method exposed by the ResourceAssignment class to split the task.
- Write the new project to the disk.
The following code shows how to accomplish these tasks:
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(SplitTasks.class);
4
5// Create new project
6Project splitTaskProject = new Project();
7
8// Get a standard calendar
9Calendar calendar = splitTaskProject.get(Prj.CALENDAR);
10
11// Set project's calendar settings
12java.util.Calendar cal = java.util.Calendar.getInstance();
13cal.set(2011, 3, 15, 8, 0, 0);
14splitTaskProject.set(Prj.START_DATE, cal.getTime());
15cal.set(2011, 3, 21, 17, 0, 0);
16splitTaskProject.set(Prj.FINISH_DATE, cal.getTime());
17
18// root task
19Task rootTask = splitTaskProject.getRootTask();
20rootTask.set(Tsk.NAME, "Root");
21
22// Add a new task
23Task taskToSplit = rootTask.getChildren().add("Task1");
24taskToSplit.set(Tsk.DURATION, splitTaskProject.getDuration(3));
25
26// Create a new resource assignment
27ResourceAssignment splitResourceAssignment = splitTaskProject.getResourceAssignments().add(taskToSplit, null);
28
29// Generate resource assignment timephased data
30splitResourceAssignment.timephasedDataFromTaskDuration(calendar);
31
32// Split the task into 3 parts.
33// Provide start date and finish date arguments to SplitTask method
34// These dates will be used for split
35// Set project's calendar settings
36cal = java.util.Calendar.getInstance();
37java.util.Calendar cal2 = java.util.Calendar.getInstance();
38
39cal.set(2011, 3, 16, 8, 0, 0);
40cal2.set(2011, 3, 16, 17, 0, 0);
41splitResourceAssignment.splitTask(cal.getTime(), cal2.getTime(), calendar);
42cal.set(2011, 3, 18, 8, 0, 0);
43cal2.set(2011, 3, 18, 17, 0, 0);
44splitResourceAssignment.splitTask(cal.getTime(), cal2.getTime(), calendar);
45splitResourceAssignment.set(Asn.WORK_CONTOUR, WorkContourType.Contoured);
46
47// Save the Project
48splitTaskProject.save(dataDir + "Project.Xml", SaveFileFormat.XML);