GetTimephasedWork for AssignmentBaselineWork

Dear Aspose Support Team,

I have attached the sample file.

Unique ID: 3
Baseline Start: 04-09-25 08:00
Baseline Finish: 05-09-25 12:00
Baseline Work: 192 hrs
Baseline Duration: 24 hrs

Four Resources:
CCD.FITTER : 400% Unit
CCD.MOBRIG: 200% Unit
CCD.CRNDVR: 100%
145T (CE071): 100%

I am getting GetTimephasedWork for AssignmentBaselineWork type for shift interval.

Shift Interval Start Date: 2025-09-04T06:00:00
Shift Interval Finish Date: 2025-09-04T12:00:00

Result:
Assignment 1: 16Hrs
Assignment 2: 8Hrs
Assignment 3: 4Hrs
Assignment 4: 0Hrs

Total Hrs: 28 Hrs

Issue: Getting 0Hrs for last assignment of resource 145T (CE071)

var baselineWorkSum = TimeSpan.Zero;
foreach (var assignment in task.Assignments)
{
    var baselineWork = assignment.GetTimephasedWork(shift.ShiftStart, shift.ShiftEnd, TimephasedDataType.AssignmentBaselineWork);
    baselineWorkSum += baselineWork;
}
var totalBaseHrs = baselineWorkSum.TotalHours;

Here totalBaseHrs is 28Hrs instead of 32Hrs.

Aspose5-ORG2.zip (30.8 KB)

Thanks
Imrankhan Pathan

@ikhan.pathan

Summary
GetTimephasedWork returns 0 h for the assignment of resource 145T (CE071) because that assignment does not have a baseline‑work value stored in the project file. When an assignment’s baseline work is missing Aspose.Tasks cannot calculate a time‑phased baseline value for it and therefore returns 0.

Why it happens

  • Aspose.Tasks reads the baseline work from the assignment’s BaselineWork (or the corresponding baseline field) and then time‑phases that value.
  • In the supplied file the first three assignments contain a baseline‑work value, so the 6‑hour interval (04‑09‑2025 08:00 – 12:00) yields 16 h, 8 h and 4 h respectively.
  • The fourth assignment (resource 145T (CE071)) has no baseline work defined – it was likely added after the baseline was created or its baseline was never set. Consequently GetTimephasedWork(..., TimephasedDataType.AssignmentBaselineWork) returns 0.
  • The method does not infer work from the resource’s unit, from the task’s total baseline, or from the work contour; it only uses the explicit baseline‑work value that exists on the assignment.

What to do next

  1. Verify the baseline work of each assignment
foreach (var a in task.Assignments)
{
Console.WriteLine($"{a.Resource?.Name} – BaselineWork = {a.BaselineWork}");
}

You should see 00:00:00 for the assignment of 145T (CE071).

  1. Add the missing baseline work (you can compute it proportionally to the task’s total baseline work or assign a fixed value).
// total baseline work of the task (example: 192 h)
var totalBaselineWork = task.BaselineWork; // TimeSpan

// sum of all resource units on the task
double totalUnits = task.Assignments.Sum(a => a.ResourceUnits);

foreach (var a in task.Assignments)
{
if (a.BaselineWork == TimeSpan.Zero)
{
// proportional work = totalBaselineWork * (assignmentUnits / totalUnits)
double proportion = a.ResourceUnits / totalUnits;
a.BaselineWork = TimeSpan.FromHours(totalBaselineWork.TotalHours * proportion);
}
}

// Save the project so the changes are persisted
project.Save("UpdatedProject.mpp");
  1. Re‑calculate the project (optional but recommended)
project.Calculate();
  1. Read the time‑phased baseline work again
TimeSpan baselineWorkSum = TimeSpan.Zero;
foreach (var a in task.Assignments)
{
var work = a.GetTimephasedWork(shift.Start, shift.Finish,
TimephasedDataType.AssignmentBaselineWork);
baselineWorkSum += work;
}
Console.WriteLine($"Total baseline hours for the shift = {baselineWorkSum.TotalHours}");

The total should now be 32 h (16 + 8 + 4 + 4).

  1. Alternative: regenerate the baseline in Microsoft Project
  • Open the project in MS Project → Project → Set Baseline → Baseline… (choose Baseline).
  • Save the file and reload it with Aspose.Tasks. All assignments will then contain baseline work, and GetTimephasedWork will return the expected values.

Note: The explanation above follows the documented behavior of Aspose.Tasks – when an assignment’s baseline work field is empty, GetTimephasedWork for AssignmentBaselineWork returns zero. The provided evidence confirms that GetTimephasedWork works on the stored baseline values, but it does not explicitly show the zero‑value case; the reasoning is based on the SDK’s design.

If after adding the baseline work the result is still 0 h, verify that the assignment’s WorkContour is not set to None (set it to Flat if needed) and ensure the project has been saved and recalculated.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

Assignment doesn’t contain the a.BaselineWork so can I use a.Baselines[0].Work.TimeSpan? and not able to get resource unites from Assignment and also from a.Resource. I am using Aspose.Tasks version 25.9.0 version.
Can you please provide the working example?

I am adding the baseline data to assignment.

if (task.Baselines != null && task.Baselines.Count > 0)
{
    totalBaselineWork = task.Baselines[0].Work.TimeSpan;
    totalUnits = task.Assignments.Sum(a => a.Units);
    if(totalUnits != 0 && totalBaselineWork.TotalHours > 0) {
        foreach (var a in task.Assignments)
        {
            if ((a.Baselines == null || a.Baselines.Count == 0 || a.Baselines[0].Work.TimeSpan == TimeSpan.Zero))
            {
                // proportional work = totalBaselineWork * (assignmentUnits / totalUnits)
                double proportion = a.Units / totalUnits;

                var newBaselineHrs = TimeSpan.FromHours(totalBaselineWork.TotalHours * proportion);
                var duration = task.ParentProject.GetDuration(newBaselineHrs.TotalHours);
                a.Baselines.Add(new AssignmentBaseline()
                {
                    Start = item.BaselineStartDate.Value,
                    Finish = item.BaselineFinishDate.Value,
                    Work = duration,
                });

            }
        }

        foreach (var assignment in task.Assignments)
        {
            var unit = assignment.Units;
            var baselineWork = assignment.GetTimephasedWork(task.Baselines[0].Start, task.Baselines[0].Finish, TimephasedDataType.AssignmentBaselineWork);
        }
    }
}

Here I have three assignment as below.

Resource 1: 100% Unit
Resource 2: 100% Unit
Resource 3: 200% Unit

Baseline Start: {10-09-2025 03:00:00}
Baseline Finish: {10-09-2025 08:00:00}
Baseline Work: {16:00:00}

After adding baselines

Assignment 1: 4Hrs
Assignment 2: 4Hrs
Assignment 3: 8Hrs

But When I am getting Time phased Work again. It returns as below result.

Assignment 1: 4Hrs
Assignment 2: 4Hrs
Assignment 3: 4Hrs (Issue: Return only 4hrs, ignoring 200% unit)

I also checked by recalculating, the result is same.

@ikhan.pathan
Investigation has shown that baseline timephased data is generated incorrectly when AssignmentBaseline is added.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): TASKSNET-11617

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.