Reputation: 33
I got a collection of 'Users' which are working on task between two dates (firstPerformance and LastPerformance) for some hours. I would like to asign that information to a task with creating asignments and setting their Start, Finish and Work:
Assignment a = task.Assignments.Add(ResourceID: user.Resource.Id);
a.Start = user.Performances.FirstPerformance;
a.Finish = user.Performances.LastPerformance;
a.Work = user.Performances.TotalTime * 60 // TotalTime is in hours while Work is in minutes
Before I do that I remove all assignments on the task and set it to pjFixedWork:
task.Type = PjTaskFixedType.pjFixedWork;
foreach (Assignment a in task.Assignments) a.Delete();
This results in strange behaivor: On the first run it sets Work and Start in Project correct and assigns the correct resource. On the second run it sets Work, Start and Finish correct And on the third run it also fixes the Unit
For example:
Of course the input is on all three runs the same!
While still not understanding this behavior I experience something different if there is more than one resource to be assigned.
The data I'm assigning looks like:
User 1 First: 14.09.2021 Last: 02.12.2021 Total Time: 82,75
User 2 First: 31.08.2021 Last: 28.01.2022 Total Time: 263,5
User 3 First: 08.09.2021 Last: 09.09.2021 Total Time: 4,5
User 4 First: 02.12.2021 Last: 02.12.2021 Total Time: 1
User 5 First: 19.10.2021 Last: 28.01.2022 Total Time: 223
User 6 First: 06.12.2021 Last: 25.01.2022 Total Time: 18,5
User 7 First: 07.09.2021 Last: 14.12.2021 Total Time: 126
The results of different runs look like:
Since I have assigned 1€/hour on the resouces I can see that something is going on since the costs are:
User 1 0,21€
User 2 2,59€
User 3 0,16€
User 4 0,07€
User 5 30,79€
User 6 9,22€
User 7 126,00€
What adds up to 169,04.
What am I doing wrong here?
Best Regards
Andreas
Upvotes: 2
Views: 214
Reputation: 378
Rachel's answer is sufficient but here's my piece for what it's worth:
Two other general things about working with resource assignments on tasks:
Upvotes: 1
Reputation: 8442
What am I doing wrong here?
Your code is not wrong. The 'wrong' part is trying to use Microsoft Project in a way it is not designed to work. Let me explain.
Microsoft Project uses a Critical Path Method algorithm to schedule tasks based on such things as duration of the tasks, links between them and other dependencies such as constraint dates and working hours (calendars). Given a set of these inputs, Project calculates task start and finish dates, work required, etc.
Problems arise when, instead of allowing the CPM algorithm to do the calculations, too many exact dates (for example) are forced into the schedule. Trying to force an exact amount of work for each resource also works against the CPM engine.
Having a task with more than a few resources is a good indication that it should be split up. Having tasks that are longer than a few weeks is also a good indication that they might be better split up. Break large tasks down into smaller parts.
Use Resource calendars to limit the availability of each resource as necessary. Use leveling to ensure resources are not overloaded. Let Project do what it does best--schedule tasks based on the constraints. Telling Project exactly when and how much each resource will work on each task is the opposite of how it is designed to be used. Don't fight it.
Upvotes: 1