Update the Project Task Actual Cost

Occasional Visitor

Hi Community

I am trying to update the Project Task's Actual Cost field value through CSOM. I read that this field is readonly can not be updated. But if from Project profession if we clear the setting Let Project Calculate Actual Cost then we can update it. I updated same setting for a project where Cost type resources are assigned.

My code runs well but the updated actual cost is not reflecting in the plan. Following is the code

foreach(DraftAssignment assignedResource in collAssgns)
{
   var resourceId = assignedResource.Id;
  draftassignresurce = assignedResource;
                 
var lookup = projContext.LoadQuery(projContext.LookupTables.Where(t => t.Name == "XYZ"));
projContext.ExecuteQuery();
foreach (LookupTable tbl in lookup)
{
projContext.Load(tbl.Entries);
projContext.ExecuteQuery();
foreach (LookupEntry entry in tbl.Entries)
{
string enId = entry.Id.ToString();
lookupTypeCustomresourcecode = entry.FullValue;
if (resourcecode == lookupTypeCustomresourcecode)
{
Console.WriteLine("Task name to be updated +"+pubtask.Name);
Console.WriteLine("Resource original actual cost: " + assignedResource.ActualCost);

draftassignresurce.ActualCost = assignedResource.ActualCost + Convert.ToDouble("1000");
collAssgns[0].ActualCost= assignedResource.ActualCost + Convert.ToDouble("1000");
projContext.ExecuteQuery();
}
}
}

}

draftProjectToUpdate.Update();
draftProjectToUpdate.Publish(true);
draftProjectToUpdate.CheckIn(true);
QueueJob qJob = projContext.Projects.Update();
projContext.WaitForQueue(qJob, 20);
projContext.ExecuteQuery();

 

Will appreciate any help on this.

0 Replies