Duration and Work not working

Hi,


I’m trying to export 2 tasks to XML with the work field set to 80 and 120 hours. Both tasks has 2 days duration.

When I open the XML file on MS-Project, both tasks’ work is set to 16 hours.

Here is a sample of my code:

Project newProject = new Project();

Task T1 = newProject.RootTask.Children.Add();
T1.Set(Tsk.Name, “Teste 1”);
T1.Set(Tsk.Start, new DateTime(2015, 9, 5));
T1.Set(Tsk.Duration, newProject.GetDuration(2, TimeUnitType.Day));
T1.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
T1.Set(Tsk.ConstraintDate, new DateTime(2015, 9, 5));
T1.Set(Tsk.Work, newProject.GetDuration(80, TimeUnitType.Hour));

Task T2 = newProject.RootTask.Children.Add();
T2.Set(Tsk.Name, “Teste 2”);
T2.Set(Tsk.Start, new DateTime(2015, 9, 11));
T2.Set(Tsk.Duration, newProject.GetDuration(2, TimeUnitType.Day));
T2.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
T2.Set(Tsk.ConstraintDate, new DateTime(2015, 9, 5));
T2.Set(Tsk.Work, newProject.GetDuration(120, TimeUnitType.Hour));

newProject.Save(“C:\TestExport.XML”, Aspose.Tasks.Saving.SaveFileFormat.XML);

I’m attaching the XML file and a printscreen.

Thanks

I found out that if I open the XML file and remove everything inside tag, it will work out.


Am I doing something wrong by not setting any assignments?

Thanks
Hi Thales,

Thank you for contacting Aspose support team.

I have reviewed the issue and tried to re-produce it using Microsoft Project 2010 (MSP). Two tasks are created in MSP using same Duration and Work values as mentioned in the sample code. This project is saved on disc as XML by MSP and opened again using MSP. It is observed that the Duration is set equivalent to Work value and work value is set to some other value. If we open and close this XML file again and again using MSP, it is observed that each time Duration and Work value is changed.

You may please set the duration equal to the Work value using Aspose.Tasks in-order to maintain the value after saving it on disc. For example if Work is 80 hours then set duration to 10 days or vice versa. If you set both the values same, these are maintained, otherwise if you don't keep them same, Aspose.Tasks will set Work value according to the duration where as MSP changes it in quite a different manner as mentioned above.

Please feel free to write us back if you have an other query in this regard.
Hello Muhammad,

Thank you for your time.

I did what you asked and it really happens with MSProject 2010 aswell.
I figured out how to do it with Aspose. I had to manage assignment of each Task, changing its work and units.

I'll paste my code here, don't know if it has any issues, but seems like everything worked fine.

Project newProject = new Project();
double units;

Task T1 = newProject.RootTask.Children.Add();
T1.Set(Tsk.Name, "Teste 1");
T1.Set(Tsk.Start, new DateTime(2015, 9, 5));
T1.Set(Tsk.Duration, newProject.GetDuration(2, TimeUnitType.Day));
T1.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
T1.Set(Tsk.ConstraintDate, new DateTime(2015, 9, 5));
T1.Set(Tsk.Work, newProject.GetDuration(80, TimeUnitType.Hour));
T1.Set(Tsk.RegularWork, newProject.GetDuration(80, TimeUnitType.Hour));
T1.Set(Tsk.RemainingWork, newProject.GetDuration(80, TimeUnitType.Hour));
ResourceAssignment assignmentT1 = T1.Assignments.First();
assignmentT1.Set(Asn.Work, newProject.GetDuration(80, TimeUnitType.Hour));
assignmentT1.Set(Asn.RegularWork, newProject.GetDuration(80, TimeUnitType.Hour));
/* units = work / (duration(days) / h/day) */
units = (double)80 / (2 * 8);
assignmentT1.Set(Asn.Units, units);


Task T2 = newProject.RootTask.Children.Add();
T2.Set(Tsk.Name, "Teste 2");
T2.Set(Tsk.Start, new DateTime(2015, 9, 11));
T2.Set(Tsk.Duration, newProject.GetDuration(2, TimeUnitType.Day));
T2.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
T2.Set(Tsk.ConstraintDate, new DateTime(2015, 9, 11));
T2.Set(Tsk.Work, newProject.GetDuration(120, TimeUnitType.Hour));

ResourceAssignment assignmentT2 = T2.Assignments.First();
assignmentT2.Set(Asn.Work, newProject.GetDuration(120, TimeUnitType.Hour));
assignmentT2.Set(Asn.RegularWork, newProject.GetDuration(120, TimeUnitType.Hour));
/* units = work / (duration(days) / h/day) */
units = (double)120 / (2 * 8);
assignmentT2.Set(Asn.Units, units);

newProject.Save("C:\\TestExport.XML", Aspose.Tasks.Saving.SaveFileFormat.XML);

Do you have any inputs about my code? I'm attaching a printscreen and the XML file.

Thank you

Hi Thales,


We have analyzed this code and found it working fine, however normally the work is not greater than the task duration. That is why Aspose.Tasks changes the work value according to the task duration. As this code sample maintains the user defined work value, thus you may please continue with this method and feel free to write us back in case of any problem or issues.