Project CSOM get remaining task work for user

417 views Asked by At

I'm making a Web API to get data from Project Online to my app in C#. I already done my connection and load my timesheets with no problem. Now my team leader asked me to get the total work scheduled for the user logged in, remaining work and work reported on each task that appears in the timesheet. This information is visible in the timesheet page if you select "View: My Work" in the options ribbon:
Project Timesheet
Work - total work scheduled for the user when the task was created
Actual Work - work hours reported until now, for the user logged in
Remaining Work - remaining work in the task for the user
I'm able to get the total work scheduled, but not the other two properties. This is the code i got so far:

context.Load(context.TimeSheetPeriods, c => c.Where(p => p.Start <= DateTime.Now && p.End >= DateTime.Now).
    IncludeWithDefaultProperties(p => p.TimeSheet,
                p => p.TimeSheet.Manager,
                p => p.TimeSheet.Manager.Email,
                p => p.TimeSheet.Lines.Where(
                    l => l.LineClass == TimeSheetLineClass.StandardLine).
                        IncludeWithDefaultProperties(l => l.Assignment,
                            l => l.Assignment.Owner.Email,
                            l => l.Assignment.Resource,
                            l => l.Assignment.Task,
                            l => l.Work)));
context.ExecuteQuery();
List<TimeSheetLine> linesList = myPeriod.TimeSheet.Lines.ToList();
foreach (TimeSheetLine x in linesList)
{
    Console.WriteLine("\nProject name: {0}; Task name: {1}; Work reported: {2}; " +
        "Planned work: {3};\n x.Assignment.RegularWork: {4}; x.Assignment.RemainingWork: {5}; x.Assignment.ActualWork: {6};",
        x.ProjectName, x.TaskName, x.Work.Where(w => w.Start.Date == DateTime.Now.Date).FirstOrDefault().ActualWork,
        x.Work.Where(w => w.Start.Date == DateTime.Now.Date).FirstOrDefault().PlannedWork,
        x.Assignment.RegularWork, x.Assignment.RemainingWork, x.Assignment.ActualWork);
}

The last row is where my problem is. x.Assignment.RegularWork gives me the Work, and in theory x.Assignment.RemainingWork should give me the Remaining Work, and x.Assignment.ActualWork the Actual Work. Should but it does not. This is the console output:

enter image description here
As you can see, x.Assignment.RegularWork matches with the Work in the timesheet, but the other two properties doesn't. Try after try this was the closest I got. Can anyone give me a hand? Thanks in advance.

0

There are 0 answers