Share via


TimeSheet.ReadTimesheetList Method

Reads a timesheet summary for the specified resource within the specified date range.

Namespace:  [TimeSheet Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/TimeSheet.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/TimeSheet.asmx?wsdl

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/ReadTimesheetList", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadTimesheetList ( _
    resUID As Guid, _
    startDate As DateTime, _
    finishDate As DateTime, _
    select As Integer _
) As TimesheetListDataSet
'Usage
Dim instance As TimeSheet
Dim resUID As Guid
Dim startDate As DateTime
Dim finishDate As DateTime
Dim select As Integer
Dim returnValue As TimesheetListDataSet

returnValue = instance.ReadTimesheetList(resUID, _
    startDate, finishDate, select)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/ReadTimesheetList", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public TimesheetListDataSet ReadTimesheetList(
    Guid resUID,
    DateTime startDate,
    DateTime finishDate,
    int select
)

Parameters

  • startDate
    Type: System.DateTime
    The date of earliest timesheet to return.
  • finishDate
    Type: System.DateTime
    The date of the most recent timesheet to return.

Return Value

Type: [TimeSheet Web service].TimesheetListDataSet
DataSet with a summary list of timesheets that satisfy the parameters.

Remarks

Use a Microsoft.Office.Project.Server.Library.TimesheetEnum.ListSelect value for the select parameter. You can combine the ListSelect values with the OR operation to filter for a combination of properties. For example, to select all timesheets that the user created that are in progress, set the select parameter to CreatedByMeORInProgress.

To return all timesheets plus an empty record for a period where there is no timesheet, set select to TimeSheetEnum.ListSelect.AllPeriods.

ReadTimesheetList ignores resUID if the value of select is just CreatedByMe. To get a list of another person's timesheets that were created by you—that is, timesheets for which you are the surrogate—pass the other user's resource GUID in resUID and a value for select that is an OR operation between CreatedByMe and InProgress, Submitted, Acceptable, Approved, Rejected, or AllExisting.

Valid dates in Project Server are January 1, 1984, through December 31, 2049.

This method uses the QueueSystem object. The CorrelationGUID property for the job is equal to the value of the TS_UID property.

Project Server Permissions

Permission

Description

Non-standard

The current user is the timesheet owner, or the value of select is CreatedByMe.

ViewResourceTimesheet

Allows a user to view timesheets for a resource. Applies only if the current user is not the timesheet owner. Global permission.

Examples

The following code sample reads all timesheets within specified dates that are created by the user and that are in progress. The sample uses the TimeSheetUtils class and the ExceptionHandlers classe to separate functionality from the Program class. The TimeSheetUtils.GetMyTimeSheetsInProgress method uses the GetCurrentUserUid method in the Resource web service to return the user's GUID.

For information about compiling the sample, see Prerequisites for ASMX-Based Code Samples.

using System;
using System.Net;
using System.Web.Services.Protocols;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.TestTimesheet
{
   class Program
   {
      private static TimeSheetWebSvc.TimeSheet timesheet =
         new TimeSheetWebSvc.TimeSheet();
      private static ResourceWebSvc.Resource resource =
         new ResourceWebSvc.Resource();

      private static TimeSheetUtils timeSheetUtils = new TimeSheetUtils();
      private static ExceptionHandlers exceptionHandlers = new ExceptionHandlers();

      [STAThread]
      static void Main()
      {
         try
         {
            const string PROJECT_SERVER_URI = "http:// ServerName/ProjectServerName/";
            const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
            const string TIMESHEET_SERVICE_PATH = "_vti_bin/psi/timesheet.asmx";

            // Set up the web service objects.
            resource.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
            resource.Credentials = CredentialCache.DefaultCredentials;

            timesheet.Url = PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH;
            timesheet.Credentials = CredentialCache.DefaultCredentials;

            // Get timesheet information for the specified dates.
            DateTime startDate = new DateTime(2006, 11, 27);
            DateTime finishDate = new DateTime(2006, 12, 1);
            Guid resUid;

            TimeSheetWebSvc.TimesheetListDataSet dsTimeSheetList = 
               timeSheetUtils.GetMyTimeSheetsInProgress(
                  timesheet, resource, startDate, finishDate, out resUid);

            Console.WriteLine("Active timesheets for resource: " + resUid.ToString());
            Console.WriteLine(string.Format("\tStart date: {0}\r\n\tFinish date: {1}", 
               startDate.ToString(), finishDate.ToString()));

            for (int i = 0; i < dsTimeSheetList.Timesheets.Count; i++)
            {
               Console.WriteLine(dsTimeSheetList.Timesheets[i].TS_UID.ToString(), 
                  dsTimeSheetList.Timesheets[i].TS_NAME);
            }
         }
         catch (SoapException ex)
         { exceptionHandlers.HandleSoapException(ex); }
         catch (WebException ex)
         { exceptionHandlers.HandleWebException(ex); }
         catch (Exception ex)
         { exceptionHandlers.HandleException(ex); }
         finally
         { exceptionHandlers.ResetConsole(); }
      }
   }

   class TimeSheetUtils
   {
      public TimeSheetUtils()
      {
      }

      // Get a list of timesheets that were created by the user and that are in progress.
      public TimeSheetWebSvc.TimesheetListDataSet GetMyTimeSheetsInProgress(
          TimeSheetWebSvc.TimeSheet timesheet,
          ResourceWebSvc.Resource resource,
          DateTime startDate,
          DateTime finishDate,
         out Guid resUid)
      {
         int select = Convert.ToInt32(
                         PSLibrary.TimesheetEnum.ListSelect.CreatedByMe
                       | PSLibrary.TimesheetEnum.ListSelect.InProgress);

         resUid = resource.GetCurrentUserUid();
         return timesheet.ReadTimesheetList(resUid, startDate, finishDate, select);
      }
   }

   class ExceptionHandlers
   {
      public ExceptionHandlers()
      {
      }

      public void HandleSoapException(SoapException ex)
      {
         PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
         PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
         string errMess = "==============================\r\nError: \r\n";
         for (int i = 0; i < errors.Length; i++)
         {
            errMess += "\n" + ex.Message.ToString() + "\r\n";
            errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n";
            errMess += errors[i].ErrId.ToString() + "\n";

            for (int j = 0; j < errors[i].ErrorAttributes.Length; j++)
            {
               errMess += "\r\n\t" + errors[i].ErrorAttributeNames()[j] + ": "
                  + errors[i].ErrorAttributes[j];
            }
            errMess += "\r\n".PadRight(30, '=');
         }
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(errMess);
      }

      public void HandleWebException(WebException ex)
      {
         string errMess = ex.Message.ToString() +
            "\n\nLog on, or check the Project Server Queuing Service";
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Error: " + errMess);
      }

      public void HandleException(Exception ex)
      {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Error: " + ex.Message);
      }

      public void ResetConsole()
      {
         Console.ResetColor();
         Console.WriteLine("\r\n\r\nPress any key...");
         Console.ReadKey();
      }
   }
}

See Also

Reference

TimeSheet Class

TimeSheet Members

TimeSheet Web Service