Work of material resource assignments gets multiplied by 8 if WorkFormat is set to Day

Suppose I want to write the following data to an mpp file:
dayyyy.png (12,4 КБ)

As you can see, Units = 1.0, Work = 1 day (selected via cursor), timephased data can be ignored.

I used the following code:

var project = new Project();

var resource = project.Resources.Add("Resource 1");
resource.Type = ResourceType.Material;

var task = project.RootTask.Children.Add("Task 1");
task.Start = new DateTime(2024, 3, 21, 8, 0, 0);
task.Duration = project.GetDuration(2, TimeUnitType.Day);
task.Finish = new DateTime(2024, 3, 22, 17, 0, 0);

var assignment = project.ResourceAssignments.Add(task, resource, 1.0d);
assignment.Start = new DateTime(2024, 3, 21, 8, 0, 0);
assignment.Work = project.GetDuration(1, TimeUnitType.Day);
assignment.Finish = new DateTime(2024, 3, 22, 17, 0, 0);

At first glance, the output file is correct, but work is measured in hours, not days.
dayhhhh.png (13,5 КБ)

So we add a line:

var project = new Project();
project.WorkFormat = TimeUnitType.Day;

The result is differet now… It’s 8 days and 8 units.
day8888.png (12,5 КБ)

Is this behavior intended? How can I get around it (besides just hardcoding division by 8)? In this particular example it’s not a big deal, and material resources have custom material labels anyway, but I work with projects that have day time unit type, and I can’t add accurate timephased data to resource assignments, because work is calculated incorrectly.

EDIT: apparently, I have found a workaround for now:

project.WorkFormat = TimeUnitType.Hour;
var assignment = project.ResourceAssignments.Add(task, resource, 1.0d);
project.WorkFormat = TimeUnitType.Day;

assignment.Start = new DateTime(2024, 3, 21, 8, 0, 0);
assignment.Work = project.GetDuration(1, TimeUnitType.Hour);
assignment.Finish = new DateTime(2024, 3, 22, 17, 0, 0);

It produces the correct result (1d, 1 unit).

EDIT2: It didn’t solve my problem, because adding timephased data to assignment and calling project.Recalculate() before saving still multiplies it by 8.

EDIT3: Here’s another solution which seems to make it calculate correctly:

project.WorkFormat = TimeUnitType.Hour;
project.Recalculate();
project.WorkFormat = TimeUnitType.Day;

Although, I’m not sure it won’t cause more problems.

@dg2358

No.
Method ResourceAssignmentCollection.Add(Task,Resource) calculates Work and Timephased Data of material resources incorrectly when project.WorkFormat is set to a value other than TimeUnitType.Hour.

1 Like

@dg2358
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-11142

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.

Okay, thank you.

I also wanted to add that values of the ResourceAssignment.Work field are read incorrectly when project.WorkFormat is set to day (e.g. 0.12 days instead of 1 day, basically it’s divided by 8).
The TimephasedDataCollection.Add(TimephasedData) method calculates values incorrectly as well.

1 Like

@dg2358 ,
thank you for the additional notes, I will add them to the ticket.

I’ve faced another issue: units with a rate scale are read incorrectly (at least for material resource assignments).
For example, the value “1/day” in MS Project shows as “0.12” in the ResourceAssignment.Units field when debugging. Not only it’s incorrect because the value is supposed to be “1” with additional data present in the RateScale field (RateScaleType.Day in this case, which is correct), but also makes it impossible to at least retrieve an accurate value (0.125 in this example) because it is rounded.
Accordingly, the value “1/week” becomes 0.02 (rounded 1/40, 40 is hours per week) and “1/month” becomes 0.01 (rounded 1/160, 160 is hours per month).
Adding assignments with a rate scale other than RateScaleType.Unspecified makes it work the other way around, e.g. adding an assignment with Units = 1 and RateScale = RateScaleType.Month leads to MS Project displaying “160/month” in the Units column.

@dg2358 ,
when you type the value of ResourceAssignment.Units, MS Project internally convert it to the hourly rate. In the same manner units are stored in MPP format. Thus we implement the same logic and ResourceAssignment.Units contains hourly unit rate.

Yes, rounding of assignment’s units lead to incorrect values in your scenario. After investigation we will remove it in a future release or add another API to get a precise values.

Yes, it’s due to that fact that ResourceAssignment.Units contain hourly rate. So the value 1D/160 should be assigned.

We will consider adding public method to make assigning of units with rate scale more user-friendly.

1 Like

@dg2358
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-11146

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.

The issues you have found earlier (filed as TASKSNET-11146,TASKSNET-11142) have been fixed in this update.
The update can be downloaded here.