Setting Daily Cost for a ResourceAssignment


We are attempting to set the daily Cost for a ResourceAssignment programmatically.

Conceptually, we would like to get the TimephaseData (type = ResourceAssignment) and then iterate through the days in the collection and *SET* the daily [Cost] Value.

The Cost is a more complex calculation that just units * resource rate, hence the need to do this external to MS Project and set the values in the *.mpp.

Basically, we are trying to do this:

ResourceAssignment ra = ...;
TimephaseData tpd = ra.GetTimephasedData(start, end, TimephasedDataType.ResourceAssignment);
foreach(TimephaseData td in tpd)
td.Value = ...; //our computed value

We desire to see our entries appear in the "Details" view of the Task Usage View in MS Project, but the above code is not cooperating...

Any assistance would be greatly appreciated,



Hi Doug,

Cost cannot be assigned directly. You need to set the rate tables of each resource in order to set the daily cost of the resource. Following is a sample code which changes the rates on different days for a resource. When we open the task usage, we can see the new cost according to the rates set on specific dates. Please give it a try and share the feedback.

Project proj = new Project(“Project2.mpp”);
Resource res1 = proj.Resources.GetByUid(1);
Rate rate1 = res1.Rates.Add(new DateTime(2016, 5, 2, 8, 0, 0));

rate1.RatesTo = new DateTime(2016, 5, 4, 8, 0, 0);
rate1.StandardRate = 6;
rate1.RateTable = RateType.A;

Rate rate2 = res1.Rates.Add(new DateTime(2016, 5, 4, 8, 0, 0));
rate2.RatesTo = new DateTime(2016, 5, 30, 8, 0, 0);
rate2.StandardRate = 4;
rate2.RateTable = RateType.A;