Sample code of adding child tasks to a parent task?

Hi,

Could you provide sample code to add children tasks to a parent task in Java?

Thanks,
Ying

Hi Ying,


Thank you for contacting Aspose support team.

Following is a sample code that demonstrate adding child tasks to parent tasks. Please give it a try and let us know your feedback.


Project proj = new Project(“D:/Aspose/Blank2010.mpp”);
proj.setNewTasksAreManual(false);
double oneDay = 8d * 60d * 60d * 10000000d;

java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2014, 9, 13,8,0,0);
Date startDate = cal.getTime();
proj.setStartDate(startDate);

Task task1 = proj.addTask(“Task 1”);
cal.set(2014, 9, 13, 8, 0, 0);
task1.setStart(cal.getTime());
task1.setDuration((long) (29 * oneDay));
Task task2 = proj.addTask(“Task 2”);

Task task3 = new Task(“Task 3”);
cal.set(2014, 9, 15,8,0,0);
task3.setStart(cal.getTime());
task3.setDuration((long) (3 * oneDay));
task3.setDurationFormat(TimeUnitType.Day);
task3.setConstraintType(ConstraintType.StartNoEarlierThan);
task3.setConstraintDate(task3.getStart());

task2.getChildren().add(task3);

Task task4 = new Task(“Task 4”);
cal.set(2014, 9, 17,8,0,0);
task4.setStart(cal.getTime());
task4.setDuration((long)(oneDay * 4));
task4.setDurationFormat(TimeUnitType.Day);
task4.setConstraintType(ConstraintType.StartNoEarlierThan);
task4.setConstraintDate(task4.getStart());

task2.getChildren().add(task4);

proj.calcTaskIds();
proj.calcTaskUids();
proj.updateReferences();
Task.recalculate(proj.getRootTask());

task3.setPercentComplete(50);
task4.setPercentComplete(70);

proj.save(“D:/Aspose/ProjectJava.mpp”, SaveFileFormat.MPP);

This worked! Thank you very much!

Do you have these Java examples online? I seems to be able to find a lot of .NET API examples but have trouble to find the same functionality for Java. I would be nice if these JAVA examples are made available online.


Hi Ying,

The Working with Tasks section of our online documentation has various examples related to Tasks. Please have a look at these for your kind reference and let us know if we can be of any additional help to you in this regard.