ResourceAssignment: Start, Finish and Duration


#1

Hi, could you help me?

I have this situation:

  • A task with two resources, when finish first resource, should start the next one.
  • Task 1 - Start - 2018/01/01 - Finish - 2018/03/23 - Duration - 60 days
  • Resource 1 - Start - 2018/01/01 - Finish 2018/01/31
  • Resource 2 - Start - 2018/02/01 - Finish 2018/03/23

Example of expected .mpp and .xml:
expect.zip (32.7 KB)

How could I code this?

I’ve tried this:

        License license = new License();
        license.SetLicense("Aspose.Tasks.lic");

        Project project = new Project("Template.mpp");

        project.CalculationMode = CalculationMode.None;

        project.Set(Prj.StartDate, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));

        Resource rsc1 = project.Resources.Add("Resource 1 (Work)");
        rsc1.Set(Rsc.Type, ResourceType.Work);
        rsc1.Set(Rsc.StandardRate, Convert.ToDecimal(1));
        rsc1.Set(Rsc.Code, "2158");

        Resource rsc2 = project.Resources.Add("Resource 2 (Work)");
        rsc2.Set(Rsc.Type, ResourceType.Work);
        rsc2.Set(Rsc.StandardRate, Convert.ToDecimal(1));
        rsc2.Set(Rsc.Code, "2159");

        Task tsk1 = project.RootTask.Children.Add("Task - 01");
        tsk1.Set(Tsk.IsManual, false);
        tsk1.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk1.Set(Tsk.Duration, project.GetDuration(30, TimeUnitType.Day));
        tsk1.Set(Tsk.Type, TaskType.FixedDuration);

        Task tsk2 = tsk1.Children.Add("Task - 01.01");
        tsk2.Set(Tsk.IsManual, false);
        tsk2.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk2.Set(Tsk.Duration, project.GetDuration(30, TimeUnitType.Day));
        tsk2.Set(Tsk.Type, TaskType.FixedDuration);

        Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
        tsk3.Set(Tsk.IsManual, false);
        tsk3.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk3.Set(Tsk.Duration, project.GetDuration(60, TimeUnitType.Day));
        tsk3.Set(Tsk.Type, TaskType.FixedDuration);

        project.Recalculate();

        ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk3, rsc1);
        assignment1.Set(Asn.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        assignment1.Set(Asn.Finish, DateTime.ParseExact("2018-01-31", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));

        ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk3, rsc2);
        assignment2.Set(Asn.Start, DateTime.ParseExact("2018-02-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        assignment2.Set(Asn.Finish, DateTime.ParseExact("2018-03-23", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));

        project.CalcResourceFields();
        project.CalcResourceStartFinish();
        

        project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
        project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);

output.zip (62.1 KB)


#2

@FabioMartins,

We are working on this query and will provide our feedback soon.


#3

@FabioMartins,

We have analyzed your code and found some anomalies. You may not set start and duration of task 1 and 2 as these are summary tasks and will be automatically adjusted based upon the child task properties. Similarly you should not set finished date of assignment but set Work of the assignment as Finish date will be calculated by the API.

We have modified your code and got the desired output, however there is an issue that we have to set unwanted Actual Start and Work for second assignment to get the correct output. This behavior is wrong as Actual values should not be used without the requirement. We need to analyze this issue in detail and have logged it under Id:TASKSNET-2653 in our issue tracking system. We will write back here as soon as some feedback is ready to share.

For your reference, following code creates the desired output.

Project project = new Project(path + "Blank2010.mpp");

project.CalculationMode = CalculationMode.None;

project.Set(Prj.StartDate, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));

Resource rsc1 = project.Resources.Add("Resource 1 (Work)");
rsc1.Set(Rsc.Type, ResourceType.Work);
rsc1.Set(Rsc.StandardRate, Convert.ToDecimal(1));
rsc1.Set(Rsc.Code, "2158");

Resource rsc2 = project.Resources.Add("Resource 2 (Work)");
rsc2.Set(Rsc.Type, ResourceType.Work);
rsc2.Set(Rsc.StandardRate, Convert.ToDecimal(1));
rsc2.Set(Rsc.Code, "2159");

Aspose.Tasks.Task tsk1 = project.RootTask.Children.Add("Task - 01");

Aspose.Tasks.Task tsk2 = tsk1.Children.Add("Task - 01.01");

Aspose.Tasks.Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
tsk3.Set(Tsk.IsManual, false);
tsk3.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
tsk3.Set(Tsk.Duration, project.GetDuration(60, TimeUnitType.Day));
tsk3.Set(Tsk.Type, TaskType.FixedDuration);


ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk3, rsc1);
assignment1.Set(Asn.Start, DateTime.ParseExact("2018-01-01 08:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture));
assignment1.Set(Asn.Work, project.GetDuration(23, TimeUnitType.Day));


ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk3, rsc2);

assignment2.Set(Asn.Start, DateTime.ParseExact("2018-02-01 08:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture));

//FOLLOWING LINE SHOULD NOT BE USED
assignment2.Set(Asn.ActualStart, DateTime.ParseExact("2018-02-01 08:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture));

assignment2.Set(Asn.Work, project.GetDuration(37, TimeUnitType.Day));

//FOLLOWING LINE SHOULD NOT BE USED
assignment2.Set(Asn.ActualWork, project.GetDuration(37, TimeUnitType.Day));

project.Recalculate();

project.CalcResourceFields();
project.CalcResourceStartFinish();


project.Save(path + @"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
project.Save(path + @"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);

#4

Hi @kashif.iqbal, any news?


#5

@FabioMartins

This issue shall possibly be fixed in our next release. Please be patient and we will update you as soon as it is fixed.


#6

Hi @MuzammilKhan, how are you?
What is the forecast for the next release?


#7

@FabioMartins

Thank you for writing back to us. The next release shall probably be available at the end of this month.


#8

Hello, is it fixed in release 18.10?


#9

@FabioMartins

We are working on this issue and it shall be fixed in next release i.e. 18.11.
Sorry for inconvenience.


#10

The issues you have found earlier (filed as TASKSNET-2653) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan


#11

Hi @MuzammilKhan, how are you?

I tested the new 18.11 release and it still could not get the expected result.

Could you explain how I should implement the code?

I really need this to work.

Tks,


#12

@FabioMartins

Thank you for your feedback.
We are working on this issue and comparing the results. You will be notified here as soon as we finish our investigation.


#13

@FabioMartins Hello!

Could you please try the code snippet given below and share your feedback on what exactly it differs from the expected result?

        Project project = new Project("Blank2010.mpp") { CalculationMode = CalculationMode.None };
        project.Set(Prj.StartDate, new DateTime(2018, 1, 1, 8, 0, 0));

        Resource rsc1 = project.Resources.Add("Resource 1 (Work)");
        rsc1.Set(Rsc.Type, ResourceType.Work);
        rsc1.Set(Rsc.StandardRate, Convert.ToDecimal(1));
        rsc1.Set(Rsc.Code, "2158");

        Resource rsc2 = project.Resources.Add("Resource 2 (Work)");
        rsc2.Set(Rsc.Type, ResourceType.Work);
        rsc2.Set(Rsc.StandardRate, Convert.ToDecimal(1));
        rsc2.Set(Rsc.Code, "2159");

        Task tsk1 = project.RootTask.Children.Add("Task - 01");
        Task tsk2 = tsk1.Children.Add("Task - 01.01");
        Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
        tsk3.Set(Tsk.IsManual, false);
        tsk3.Set(Tsk.Start, new DateTime(2018, 1, 1, 8, 0, 0));
        tsk3.Set(Tsk.Duration, project.GetDuration(60, TimeUnitType.Day));
        tsk3.Set(Tsk.Type, TaskType.FixedDuration);

        ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk3, rsc1);
        assignment1.Set(Asn.Start, new DateTime(2018, 1, 1, 8, 0, 0));
        assignment1.Set(Asn.Work, project.GetDuration(23, TimeUnitType.Day));

        ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk3, rsc2);
        assignment2.Set(Asn.Start, new DateTime(2018, 2, 1, 8, 0, 0));
        assignment2.Set(Asn.Work, project.GetDuration(37, TimeUnitType.Day));

        project.Recalculate();
        project.RecalculateResourceFields();
        project.RecalculateResourceStartFinish();

Thank you.


#14

Hi @alexanderefremov1,

Attached print: ResourceFinish.png (118.6 KB)

Resource 1 started on 2018-01-01 and the duration of 23 days has been set, the finish date is correct on 2018-04-25.

Resource 2 started on 2018-02-01 and the duration was set to 37 days, but the finish date is wrong on 2018-02-01. The expected would be 2018-02-01 + 37 days.

Am I correct with this statement?

Tks,


#15

@FabioMartins

Thank you for your feedback.
We have recorded the details and will consider it during the issue resolution.


#16

@FabioMartins
Thank you for your feedback. We have tested it again with our latest Aspose.Tasks version which is under development and we cannot reproduce the issue. To investigate in details, could you please share your Template.mpp file?


#17

Template.zip (20.7 KB)
Could you provide your test code and template? To check here too


#18

@FabioMartins

Thank you for your feedback.
It is requested to kindly test with our latest version Aspose.Tasks for .NET 18.12 and share your feedback. Meanwhile, we investigate it further and will update you soon.


#19

Hello, I tried with 18.12, but still did not get the expected result. Can you help me?

using System;
using Aspose.Tasks;
using Aspose.Tasks.Saving;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            License license = new License();
            license.SetLicense("Aspose.Tasks.lic");

            //Project project = new Project("Template.mpp");

            Project project = new Project("Template.mpp") { CalculationMode = CalculationMode.None };
            project.Set(Prj.StartDate, new DateTime(2018, 1, 1, 8, 0, 0));

            Resource rsc1 = project.Resources.Add("Resource 1 (Work)");
            rsc1.Set(Rsc.Type, ResourceType.Work);
            rsc1.Set(Rsc.StandardRate, Convert.ToDecimal(1));
            rsc1.Set(Rsc.Code, "2158");

            Resource rsc2 = project.Resources.Add("Resource 2 (Work)");
            rsc2.Set(Rsc.Type, ResourceType.Work);
            rsc2.Set(Rsc.StandardRate, Convert.ToDecimal(1));
            rsc2.Set(Rsc.Code, "2159");

            Task tsk1 = project.RootTask.Children.Add("Task - 01");
            Task tsk2 = tsk1.Children.Add("Task - 01.01");
            Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
            tsk3.Set(Tsk.IsManual, false);
            tsk3.Set(Tsk.Start, new DateTime(2018, 1, 1, 8, 0, 0));
            tsk3.Set(Tsk.Duration, project.GetDuration(60, TimeUnitType.Day));
            tsk3.Set(Tsk.Type, TaskType.FixedDuration);

            ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk3, rsc1);
            assignment1.Set(Asn.Start, new DateTime(2018, 1, 1, 8, 0, 0));
            assignment1.Set(Asn.Work, project.GetDuration(23, TimeUnitType.Day));

            ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk3, rsc2);
            assignment2.Set(Asn.Start, new DateTime(2018, 2, 11, 8, 0, 0));
            assignment2.Set(Asn.Work, project.GetDuration(37, TimeUnitType.Day));

            project.Recalculate();
            project.RecalculateResourceFields();
            project.RecalculateResourceStartFinish();

            project.Save(@"output.xml", SaveFileFormat.XML);
            project.Save(@"output.mpp", SaveFileFormat.MPP);
        }
            
    }
}

Template.zip (20.7 KB)
output.zip (21.6 KB)

How could I implement the generation of this situation?

  • Task with two resources, when finish first resource, should start the next one.
  • Task 1 - Start - 2018/01/01 - Finish - 2018/03/23 - Duration - 60 days
  • Resource 1 - Start - 2018/01/01 - Finish 2018/01/31
  • Resource 2 - Start - 2018/02/01 - Finish 2018/03/23

Could you send a code, for that?


#20

@FabioMartins

Thank you for your feedback.
Please give us some time to investigate it further and we will share our findings soon.