2

I'm developing a small code that makes possible to read from database some values in order to do the Timesheets for all of employees of a corporation.

The data of the database comes from another app where Project Managers define all the task changes like reassign tasks.

The code works well when the task starts and ends with the same employee that was set from Project Manager at the start of the project tasks definition.

The issue is when Project Manager decides/needs to change the employee who is doing the task with other one for any reason. Then I got the problem that the Timesheet of the new employee doesn't have the Project Line in order to fill the Timesheet with my app.

So my question is: - Is there any way to include the new lines to the new employee timesheet?

Thanks in advance.

EDIT:

I would like to add how I'm doing the fill of timesheet:

// I'm getting my period here --> Before I authenticate the user against Project Context

   var myPeriod = projContext.TimeSheetPeriods.FirstOrDefault();

    foreach (var l in myPeriod.TimeSheet.Lines)
    {
       for (int i = 0; i < TimesheetTaskId.Count; i++)
       {
          projContext.Load(projContext.Projects);
          projContext.ExecuteQuery();

          var proj = projContext.Projects.First(p => p.Id == Guid.Parse(projectid.ElementAt(i)));
          projContext.ExecuteQuery();

          if (l.Id == Guid.Parse(TimesheetTaskId.ElementAt(i)))
             {
                for (int x = 0; x < taskid.Count; x++)
                {
                   draftProj = proj.CheckOut();
                   var plannedwork = l.Work.Where(w => w.Id == Guid.Parse(TimesheetTaskId.ElementAt(i))).FirstOrDefault();

                   TimeSheetWorkCreationInformation workCreation = new TimeSheetWorkCreationInformation
                   {

                      ActualWork = string.Format("{0}h", actualwork.ElementAt(x)), // Worked hours
                      Start = date.ElementAt(x),
                      End = date.ElementAt(x),
                      Comment = "From CSOM",
                      NonBillableOvertimeWork = "0",
                      NonBillableWork = "0",
                      OvertimeWork = "0",
                      PlannedWork = plannedwork == null ? "0h" : plannedwork.PlannedWork
                   };

                l.Work.Add(workCreation);
                myPeriod.TimeSheet.Update();

             }

          }
          draftProj.CheckIn(true);
      }

    }

As you can see, during the foreach sentence I create an object type 'TimeSheetWorkCreationInformation' which allows me to fill the Timesheet if there are any work lines in it.

When we make the reassign, the timesheet of the new resource doesn't have the new work lines.

Remembering again my question: - Is there any way to include the new lines to the new employee timesheet?

Thanks

Marc Lluis
  • 61
  • 7

0 Answers0