Duration is set to 0 on a manually scheduled task in CalculationMode.None when assignment is added

Hi,


I’m creating a project from scratch from a MPP file (2010+ format). Apose 9.6.0 on Java.

I want full control on the task schedule, so tasks are Manually Scheduled, and Project CalculationMode is set to NONE.

When I only set the task fields everything works fine, but whenever I add an assignment, the duration of the task is set to 0.
I guess I must do something wrong, as it’s easy to overlook a field in CalculationMode None. Any idea what I’m doing wrong?

Task and assignment have the same info, i.e. 16 hours of work of which 8 hours have already been completed.

I’m setting both Duration/Start/Finish fields and ManualDuration/ManualStart/ManualFinish fields, could that cause some issues?

Here’s my code:

// License loading code omitted

<span style=“font-family: “Courier New”;”> <span style=“font-family: “Courier New”;”> Project asProject = new Project(“C:\temp\Project_blank.mpp”);

asProject.setCalculationMode(CalculationMode.None);

// Setting basic task info - no problem
com.aspose.tasks.Task asTask = asProject.getRootTask().getChildren().add(“Task1”);
asTask.set(Tsk.ID, 1);
asTask.set(Tsk.UID, 1);
asTask.set(Tsk.IS_MANUAL, new NullableBool(true));
asTask.set(Tsk.DURATION, asProject.getDuration(2, TimeUnitType.Day));
asTask.set(Tsk.MANUAL_DURATION, asProject.getDuration(2, TimeUnitType.Day));
Date start = new SimpleDateFormat(“MM/dd/yyyy HH:mm:ss”).parse(“11/14/2016 08:00:00”);
Date finish = new SimpleDateFormat(“MM/dd/yyyy HH:mm:ss”).parse(“11/15/2016 16:00:00”);
asTask.set(Tsk.START, start);
asTask.set(Tsk.MANUAL_START, start);
asTask.set(Tsk.FINISH, finish);
asTask.set(Tsk.MANUAL_FINISH, finish);
asTask.set(Tsk.WORK, asProject.getDuration(16, TimeUnitType.Hour));
asTask.set(Tsk.ACTUAL_START, start);
asTask.set(Tsk.ACTUAL_WORK, asProject.getDuration(8, TimeUnitType.Hour));
asTask.set(Tsk.REMAINING_WORK, asProject.getDuration(8, TimeUnitType.Hour));
asTask.set(Tsk.PERCENT_COMPLETE, 50);
asTask.set(Tsk.PERCENT_WORK_COMPLETE, 50);

Resource asResource = asProject.getResources().add(“John Doe”);

asProject.save(“c:\temp\Project_task_info_ok.mpp”, SaveFileFormat.MPP);

// Setting assignment info - messes up initial information

ResourceAssignment ra = asProject.getResourceAssignments().add(asTask, asResource);

ra.set(Asn.START, start);
ra.set(Asn.WORK, asProject.getDuration(16, TimeUnitType.Hour));
ra.set(Asn.PERCENT_WORK_COMPLETE, 50);
ra.set(Asn.ACTUAL_START, start);
ra.set(Asn.ACTUAL_WORK, asProject.getDuration(8, TimeUnitType.Hour));

asProject.save(“c:\temp\Project_task_with_assignment_not_ok.mpp”, SaveFileFormat.MPP);


Thanks,
Etienne.

Hi Etienne,


Thank you for contacting Aspose support team.

I have tested the scenario by executing the code and observed that duration is not set to 0 after the assignment. I have opened the resultant file in MSP 2010 and image is attached for your reference. Could you please verify the duration value after the assignment and share the version of MSP used in the testing? Please send us the image of the resultant file while opened in MSP.

Hi Kashif,


I’m using MSP 2016.

Even with your example, how do you explain a duration value of 1.88? Is there any reason why the duration value should not be 2?

Hi Etienne,


Thank you for providing more information.

The “Project_blank.mpp” used in this testing contains working hours which are from 08:00 to 17:00, however in the above mentioned sample code, task finish time is set to 16:00. This causes the duration to set slightly less than 2 days i.e. 1.88 days.

You may use asProject.recalculate() before saving the project to MPP file to get the proper result i.e. duration 2 days.

Please give a try to the following code and share the feedback.

<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”>“Project_blank.mpp”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);



asProject.setCalculationMode(CalculationMode.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>None
<span style=“font-size: 9pt; font-family: “Courier New”;”>);



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>// Setting basic task info - no problem

<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”;”>);

asTask.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>ID
<span style=“font-size: 9pt; font-family: “Courier New”;”>, <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”;”>);

asTask.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>UID
<span style=“font-size: 9pt; font-family: “Courier New”;”>, <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”;”>);

asTask.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>IS_MANUAL
<span style=“font-size: 9pt; font-family: “Courier New”;”>, <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”;”>NullableBool(<span style=“font-size:9.0pt;font-family:
“Courier New”;mso-fareast-font-family:“Times New Roman”;color:navy”>true
<span style=“font-size: 9pt; font-family: “Courier New”;”>));

asTask.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”>2<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”;”>));

asTask.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>MANUAL_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”>2<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”;”>));

Date start = <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>null
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

Date finish = <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>null
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:navy”>try
<span style=“font-size: 9pt; font-family: “Courier New”;”>{

start = <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”>“11/14/2016
08:00:00”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

finish = <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”>“11/15/2016
17:00:00”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);



} <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:navy”>catch
<span style=“font-size: 9pt; font-family: “Courier New”;”>(ParseException
e) {

e.printStackTrace();

}

asTask.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”;”>, start);

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

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

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

asTask.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>WORK
<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”>16<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”>Hour
<span style=“font-size: 9pt; font-family: “Courier New”;”>));

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

asTask.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>ACTUAL_WORK
<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”>8<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”>Hour
<span style=“font-size: 9pt; font-family: “Courier New”;”>));

asTask.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>REMAINING_WORK
<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”>8<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”>Hour
<span style=“font-size: 9pt; font-family: “Courier New”;”>));

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

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



Resource asResource = asProject.getResources().add(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“John Doe”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);



asProject.recalculate();

asProject.save(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“Project_task_info_ok.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”;”>);



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>// Setting assignment info - messes up initial
information



<span style=“font-size: 9pt; font-family: “Courier New”;”>ResourceAssignment ra =
asProject.getResourceAssignments().add(asTask, asResource);



ra.set(Asn.<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”;”>, start);

ra.set(Asn.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>WORK
<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”>16<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”>Hour
<span style=“font-size: 9pt; font-family: “Courier New”;”>));

ra.set(Asn.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>PERCENT_WORK_COMPLETE
<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>50<span style=“font-size: 9pt; font-family: “Courier New”;”>);

ra.set(Asn.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>ACTUAL_START
<span style=“font-size: 9pt; font-family: “Courier New”;”>, start);

ra.set(Asn.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>ACTUAL_WORK
<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”>8<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”>Hour
<span style=“font-size: 9pt; font-family: “Courier New”;”>));



asProject.recalculate();

asProject.save(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“Project_task_with_assignment_ok.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,


Thanks for the working day info.

I understand that calling project.calculate() will iron out any missing/incorrect value, but what I’m trying to do is to set all required fields manually without having to call project.calculate() - mostly for performance & field value control reasons.

Is there any way to do so?

Hi Etienne,


Thank you for writing to Aspose support team again.

I have logged this issue in our issue tracking system under Id:TASKSJAVA-266 for further investigation by the product team. You will be automatically notified once any update is received in this regard.