none
Is approval of timesheet update possible using CSOM or REST? RRS feed

  • Question

  • Hi,

    Is there any way to approve a timesheet update using CSOM or REST for Project Online?

    Using CSOM, I tried to forcefully set the timesheet status as Approved using the following piece of code(using the context of the same user whose timesheet I wish to approve; since I can't load properties of timesheet using other user's context). The code didn't give me any error but also didn't change the status of timesheet.

    public static void TimesheetApprovalCheck(Guid timesheetId, Guid periodId, DateTime startDate)
    {
        using (projectContext)
                {
    
                    projectContext.Load(projectContext.TimeSheetPeriods, c => c.Where(p => p.Start == startDate && p.Id == periodId).
                       Include(p => p.TimeSheet));      
                    projectContext.ExecuteQuery();
    
                    var period = projectContext.TimeSheetPeriods.FirstOrDefault();
                    period.TimeSheet.Status = TimeSheetStatus.Approved;
                    period.TimeSheet.Update();
                    projectContext.ExecuteQuery();
    
                }
    }

     I tried to use the "_api/projectserver/TimeSheetPeriods('[guid]')/TimeSheet" REST endpoint also to update but all in vain. Is there any way we can access the Approval Center of a timesheet manager programmatically and approve a timesheet update?

    I am stuck. Please help me if there is something wrong with my approach or the above code, or if there is any other way I can accomplish this.

    Thursday, June 13, 2019 5:11 AM

All replies

  • I have never been able to do anything in the context of anyone else... if you figure it out, please share!

    Regarding your overall use-case... what are you trying to accomplish? We set our resources as their own timesheet managers so timesheets auto-approve. We also have PMs set up an auto-approval rule so task updates go through as well. This leaves nothing needing an approval.


    Ian

    Thursday, June 13, 2019 3:35 PM
  • Hi Ian,

    Thank you for the prompt reply. 

    I am trying to set up a lazy approval process of submitted timesheets in Project Online wherein the submitted timesheet can be approved by the timesheet manager through mail without any need to visit the PWA site. (considering that all resources have some other resource as their timesheet manager and not themselves)

    Please let me know if there is a way to achieve the above functionality. 

    Friday, June 14, 2019 5:12 AM
  • Here, we decided to stop requiring timesheet approval by a manager. Instead, managers can review a report post hoc. We found timesheet submission dropping when supervisors weren't regularly approving on time... and if the supervisors weren't approving, the submitters started having good reason to question why they were having to submit. Our goal is timely and reasonably accurate submission... not necessarily supervisor approved. In addition to being able to review the submissions after they're auto-approved, supervisors also see a report that names unsubmitted timesheets, which we define as timesheets with an active assignment... That way no one is forced to submit a timesheet during a time period where they didn't have assignments.

    I can't think of anything in project online directly you could run... but perhaps by using a scheduled 365 flow, you could poll for submitted timesheets, email the timesheet manager and approval with the PowerApps approval actions, and on receipt in flow send an http message to project online to approve the timesheet... that would have to run on a service account with the right permissions... but I'm trying to think if that's possible if the timesheet is waiting in someone else's' queue to approve it.

    Perhaps some different functionality will come at the end of the year/next year with the new "project service", whatever that's going to entail.


    Ian

    Friday, June 14, 2019 12:50 PM