Start Date and Finish Date is incorrect

Hi,

Please try the code below, the start date and finish date will disappear, I attached "Empty_Project.mpp".

public static void main(String[] args) throws ParseException {
FileInputStream fstream = null;
try {
// Create a stream object containing the license file
fstream = new FileInputStream("Aspose.Tasks.lic");
// Instantiate the License class
License license = new License();
// Set the license through the stream object
license.setLicense(fstream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
fstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Project asProject = new Project("Empty_Project.mpp");
com.aspose.tasks.Task asTask = asProject.getRootTask().getChildren().add("Task1");
Date dateTask = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("1/5/2004 08:00:00");
asTask.set(Tsk.DURATION, asProject.getDuration(5, TimeUnitType.Day));
asTask.set(Tsk.START, dateTask);
com.aspose.tasks.Task asTaskSub1 = asTask.getChildren().add("Task1-sub1");
Date dateTaskSub1 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("1/5/2004 08:00:00");
asTaskSub1.set(Tsk.DURATION, asProject.getDuration(1, TimeUnitType.Day));
asTaskSub1.set(Tsk.START, dateTaskSub1);
com.aspose.tasks.Task asTaskSub2 = asTask.getChildren().add("Task1-sub2");
Date dateTaskSub2 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("1/6/2004 08:00:00");
asTaskSub2.set(Tsk.DURATION, asProject.getDuration(4, TimeUnitType.Day));
asTaskSub2.set(Tsk.START, dateTaskSub2);
asProject.save("output.mpp", SaveFileFormat.MPP);
}

Hi Zhencheng,


Thank you for contacting Aspose support team.

You may please use OutlineIndent function to create parent and child tasks. Following is a sample code which generates the required output. Snapshot of the output file is attached here for your reference.

<span style=“font-size: 9pt; font-family: “Courier New”;”>Project asProject = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>new
<span style=“font-size: 9pt; font-family: “Courier New”;”>Project(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Empty_Project.mpp”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

com.aspose.tasks.Task asTask = asProject.getRootTask().getChildren().add(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Task1”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);



com.aspose.tasks.Task asTaskSub1 = asProject.getRootTask().getChildren().add(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Task1-sub1”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

Date dateTaskSub1 = <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>new
<span style=“font-size: 9pt; font-family: “Courier New”;”>SimpleDateFormat(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:green”>“MM/dd/yyyy
HH:mm:ss”
<span style=“font-size: 9pt; font-family: “Courier New”;”>).parse(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“1/5/2004 08:00:00”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

asTaskSub1.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>DURATION
<span style=“font-size: 9pt; font-family: “Courier New”;”>, asProject.getDuration(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>1<span style=“font-size: 9pt; font-family: “Courier New”;”>, TimeUnitType.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Day
<span style=“font-size: 9pt; font-family: “Courier New”;”>));

asTaskSub1.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>START
<span style=“font-size: 9pt; font-family: “Courier New”;”>, dateTaskSub1);

asTaskSub1.outlineIndent();



com.aspose.tasks.Task asTaskSub2 = asProject.getRootTask().getChildren().add(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Task1-sub2”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

Date dateTaskSub2 = <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>new
<span style=“font-size: 9pt; font-family: “Courier New”;”>SimpleDateFormat(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:green”>“MM/dd/yyyy
HH:mm:ss”
<span style=“font-size: 9pt; font-family: “Courier New”;”>).parse(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“1/6/2004 08:00:00”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

asTaskSub2.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>DURATION
<span style=“font-size: 9pt; font-family: “Courier New”;”>, asProject.getDuration(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>4<span style=“font-size: 9pt; font-family: “Courier New”;”>, TimeUnitType.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Day
<span style=“font-size: 9pt; font-family: “Courier New”;”>));

asTaskSub2.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>START
<span style=“font-size: 9pt; font-family: “Courier New”;”>, dateTaskSub2);

asTaskSub2.outlineIndent();



asProject.save(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“output.mpp”
<span style=“font-size: 9pt; font-family: “Courier New”;”>, SaveFileFormat.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>MPP
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

Hi Kashif,


Is your proposition considered to be a workaround for an existing issue or is it the “recommended” use of Aspose API? Because it’s not how your current documentation recommends to create sub tasks (Creating Tasks).

This way of creating sub-tasks is fine if we decide to generate a work plan from scratch, but it will be very complicated to create new sub-tasks under a task already existing in the work plan.

Shouldn’t an issue be created about this?

Kind Regards,
Etienne.

(Sorry, previous message was posted while logged in with the wrong account)

Hi Kashif,

Try below code, you will find that the start and finish date of Task2-sub2 disappeard.

Project asProject = new Project("Empty_Project.mpp");
com.aspose.tasks.Task asTask = asProject.getRootTask().getChildren().add("Task1");

com.aspose.tasks.Task asTaskSub1 = asProject.getRootTask().getChildren().add("Task1-sub1");
Date dateTaskSub1 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("1/5/2004 08:00:00");
asTaskSub1.set(Tsk.DURATION, asProject.getDuration(1, TimeUnitType.Day));
asTaskSub1.set(Tsk.START, dateTaskSub1);
asTaskSub1.outlineIndent();
com.aspose.tasks.Task asTaskSub2 = asProject.getRootTask().getChildren().add("Task1-sub2");
Date dateTaskSub2 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("1/5/2004 08:00:00");
asTaskSub2.set(Tsk.DURATION, asProject.getDuration(2, TimeUnitType.Day));
asTaskSub2.set(Tsk.START, dateTaskSub2);
asTaskSub2.outlineIndent();
com.aspose.tasks.Task asTask2 = asProject.getRootTask().getChildren().add("Task2");

com.aspose.tasks.Task asTask2Sub1 = asProject.getRootTask().getChildren().add("Task2-sub1");
Date dateTask2Sub1 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("1/5/2004 08:00:00");
asTask2Sub1.set(Tsk.DURATION, asProject.getDuration(1, TimeUnitType.Day));
asTask2Sub1.set(Tsk.START, dateTask2Sub1);
asTask2Sub1.outlineIndent();
com.aspose.tasks.Task asTask2Sub2 = asProject.getRootTask().getChildren().add("Task2-sub2");
Date dateTask2Sub2 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("1/5/2004 08:00:00");
asTask2Sub2.set(Tsk.DURATION, asProject.getDuration(2, TimeUnitType.Day));
asTask2Sub2.set(Tsk.START, dateTask2Sub2);
asTask2Sub2.outlineIndent();
asProject.save("output.mpp", SaveFileFormat.MPP);

Hi Zhencheng,


The method to create sub-tasks by adding tasks to Children collection or using OutlineIndent method both are correct and can be used alternatively as per requirement. It seems to be a bug where empty start/finish dates are displayed using code sample in your first post here and second code sample in last post here.

This issue is logged under Id: TASKSJAVA-219 for further consideration by the product team. You will be automatically notified once any update is received in this regard.

Hi kashif,


I found that there is no problem in the 8.8.0 version, the defect happened in the 9.3.0 version.

Hi Zhencheng,


Thank you for sharing the information. I have passed it to developers for their consideration.

The issues you have found earlier (filed as TASKSJAVA-219) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.