The issue about resource and actual finish

The code is below:


public static void main(String[] args) {
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(“Project_blank.mpp”);

com.aspose.tasks.Resource asResource = asProject.getResources().add(“test”);
for (int i = 0; i < 10; i++) {
final long startTime = System.currentTimeMillis();

Task asTask = asProject.getRootTask().getChildren().add(“Root task” + i);

Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
asTask.set(Tsk.START, cal1.getTime());
asTask.set(Tsk.FINISH, cal2.getTime());
asTask.set(Tsk.DURATION, asProject.getDuration(4, TimeUnitType.Day));
asTask.set(Tsk.WORK, asProject.getDuration(4, TimeUnitType.Hour));
asTask.set(Tsk.UID, i);

asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));
asTask.set(Tsk.IS_CRITICAL, new NullableBool(false));
asTask.set(Tsk.ACTUAL_START, cal1.getTime());
asTask.set(Tsk.ACTUAL_FINISH, cal2.getTime());
asTask.set(Tsk.ACTUAL_DURATION, asProject.getDuration(4, TimeUnitType.Day));
asTask.set(Tsk.START, cal1.getTime());
asTask.set(Tsk.FINISH, cal2.getTime());
asTask.set(Tsk.UID, i);

asTask.set(Tsk.WORK, asProject.getDuration(8));
asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));
asTask.set(Tsk.NAME, “test” + i);

Integer type = 2;
if (type != null) {
asTask.set(Tsk.CONSTRAINT_TYPE, type.intValue());
}

asTask.set(Tsk.CONSTRAINT_DATE, cal1.getTime());

asTask.set(Tsk.PRIORITY, 500);

asTask.set(Tsk.IS_CRITICAL, new NullableBool(true));

asTask.set(Tsk.TOTAL_SLACK, 3);
asTask.set(Tsk.ACTUAL_START, cal1.getTime());
asTask.set(Tsk.ACTUAL_FINISH, cal2.getTime());

asTask.set(Tsk.ACTUAL_DURATION, asProject.getDuration(4, TimeUnitType.Day));
asTask.set(Tsk.PERCENT_COMPLETE, 90);
asTask.set(Tsk.REMAINING_WORK, asProject.getDuration(16));
asProject.getResourceAssignments().add(asTask, asResource);
final long endTime = System.currentTimeMillis();
System.out.println("Total execution time: " + (endTime - startTime));

System.out.println(i);
}
// Save the Project
asProject.save(“task-resource.mpp”, SaveFileFormat.MPP);
System.out.println(“ok”);

}

Open the MPP file, the issue is that the actual finish display ‘N/A’, but when I delete the line ‘com.aspose.tasks.Resource asResource = asProject.getResources().add(“test”);’, the actual finish has correct value.

Hi Zhencheng,


Thank you for contacting Aspose support team.

I have reviewed the code and observed that you are setting task UID yourself. It is causing error in the output. You may please comment these lines of code at two positions, run the tests again and share the feedback with us.

Project asProject = new Project("Blank2010.mpp");
com.aspose.tasks.Resource asResource = asProject.getResources().add("test");for(int i = 0; i < 10; i++)
{
    System.out.println("Task = " + i);
    final long startTime = System.currentTimeMillis();
    Task asTask = asProject.getRootTask().getChildren().add("Root task" + i);
    java.util.Calendar cal1 = java.util.Calendar.getInstance();
    java.util.Calendar cal2 = java.util.Calendar.getInstance();

    asTask.set(Tsk.START, cal1.getTime());
    asTask.set(Tsk.FINISH, cal2.getTime());
    asTask.set(Tsk.DURATION, asProject.getDuration(4, TimeUnitType.Day));

    asTask.set(Tsk.WORK, asProject.getDuration(4, TimeUnitType.Hour));
    //comment this line 
    //asTask.set(Tsk.UID, i);
    asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));
    asTask.set(Tsk.IS_CRITICAL, new NullableBool(false));
    asTask.set(Tsk.ACTUAL_START, cal1.getTime());
    asTask.set(Tsk.ACTUAL_FINISH, cal2.getTime());
    asTask.set(Tsk.ACTUAL_DURATION, asProject.getDuration(4, TimeUnitType.Day));
    asTask.set(Tsk.START, cal1.getTime());
    asTask.set(Tsk.FINISH, cal2.getTime()); 
    //comment this line //asTask.set(Tsk.UID, i);
    asTask.set(Tsk.WORK, asProject.getDuration(8));
    asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));
    asTask.set(Tsk.NAME, "test" + i);
    Integer type = 2;
    if (type != null)
    {
        asTask.set(Tsk.CONSTRAINT_TYPE, type.intValue());
    }

    asTask.set(Tsk.CONSTRAINT_DATE, cal1.getTime());
    asTask.set(Tsk.PRIORITY, 500);
    asTask.set(Tsk.IS_CRITICAL, new NullableBool(true));
    asTask.set(Tsk.TOTAL_SLACK, 3);
    asTask.set(Tsk.ACTUAL_START, cal1.getTime());
    asTask.set(Tsk.ACTUAL_FINISH, cal2.getTime());
    System.out.println(cal2.getTime());
    asTask.set(Tsk.ACTUAL_DURATION, asProject.getDuration(4, TimeUnitType.Day)); 
    asTask.set(Tsk.PERCENT_COMPLETE, 90);
    asTask.set(Tsk.REMAINING_WORK, asProject.getDuration(16));
    asProject.getResourceAssignments().add(asTask, asResource);
    final long endTime = System.currentTimeMillis();
    System.out.println("Total execution time: " + (endTime - startTime));
    System.out.println(i); 
}

// Save the Project
asProject.save("task-resource.mpp", SaveFileFormat.MPP);
System.out.println("ok");

Hi,

Do you have find the actual finish issue? I have set the value of actual finish, but when I opened the file “task-resource.mpp” that I saved by “asProject.save”, it will display “N/A”.

Hi Zhencheng,


If I run the above mentioned code and open the resultant MPP file in MSP 2010, the actual start and actual finish dates are properly displayed and no NA is observed. Snapshot of the MPP file opened in MSP 2010 is attached here for your reference.

Should you have any other query in this regard, please feel free to write us back.

In fact, My project version is 2013, let me check it in 2010 first.

Hi Zhencheng,


I have observed the difference in display of resultant MPP file in MSP 2010 and MSP 2013. In MSP 2013 it displays Actual Finish date as NA and there are other differences as well.

However before logging this issue, I need to share that if Percent complete is set less than 100%, Microsoft project also sets the Actual finish date to NA. However, if we set percent complete to 100%, then Actual Finish date is set properly by MSP and Aspose.Tasks as well. Please set percent complete values as mentioned above and share the feedback. Also it is recommended that avoid setting the task finish date and set start and duration only.

Once the Actual Finish date behavior is verified, I will log the issue where resultant file is displayed different in MSP 2010 and MSP 2013.

Hi,

I want to know if set the MSP UID by the API of Aspose, anything wrong with it?

Hi Zhencheng,


You can set the UID yourself as well. Just modify your code here such that task UID start from 1
rather than 0. Please un-comment following line in the sample code such that UID start from 1. As loop is running from 0 to 9, therefore it will set the UID of first task from 1. Please give it a try and share the feedback.

asTask.set(Tsk.UID, i + 1);

Hi Kashif,


How is it going? Can you give me the ticket number so I can track it?

Hi,


We shared the information with you. Could you please share your feedback with us after making the changes we suggested to you above? The issue will be logged in light of your feedback for further analysis by our Product team.