Skip to Content

Time Sheet in SAP Business One SDK

About Time Sheet:

The Time Sheet feature enables you to record times of activities for an employee, user, or others.

To access this window, from the SAP Business One Main Menu, choose

Human Resources → Time Sheet

A detailed information about the Time Sheet can be found from the following ‘How to Guide for SAP Business One Version 9.2 and SAP Business One 9.2, version for SAP HANA’ .

https://help.sap.com/http.svc/rc/012002523100002810972016e/9.2/en-US/HTG_B1_92_ProjectMgmt.pdf

Using Time Sheet in SAP Business One SDK:

Time Sheet object is exposed as a Service Type Object (ProjectManagementTimeSheetService) from SAP Business One Version 9.2 PL03. It is yet to be implemented in DTW.

Here is how to use the Time Sheet object using DI API:

1. Add a Time Sheet using DI API:

SAPbobsCOM.CompanyService oCompanyService = default(SAPbobsCOM.CompanyService);
SAPbobsCOM.ProjectManagementTimeSheetService oTimeSheetService = null;
oCompanyService = oCompany.GetCompanyService();
oTimeSheetService = (SAPbobsCOM.ProjectManagementTimeSheetService)oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.ProjectManagementTimeSheetService);
SAPbobsCOM.PM_TimeSheetData oTimeSheet = oTimeSheetService.GetDataInterface(SAPbobsCOM.ProjectManagementTimeSheetServiceDataInterfaces.pmtssPM_TimeSheetData);
SAPbobsCOM.PM_TimeSheetParams oTimeSheetParam = oTimeSheetService.GetDataInterface(SAPbobsCOM.ProjectManagementTimeSheetServiceDataInterfaces.pmtssPM_TimeSheetParams);
oTimeSheet.TimeSheetType = SAPbobsCOM.TimeSheetTypeEnum.tsh_Employee;
oTimeSheet.UserID = 1;
SAPbobsCOM.PM_TimeSheetLineData oTimeSheetLine = oTimeSheet.PM_TimeSheetLineDataCollection.Add();
DateTime startTime, endTime, breakTime, nonBillableTime;
startTime = DateTime.Today;
startTime = startTime.AddHours(10);
startTime = startTime.AddMinutes(30);
endTime = DateTime.Today;
endTime = endTime.AddHours(16);
endTime = endTime.AddMinutes(30);
breakTime = DateTime.Today;
breakTime = breakTime.AddMinutes(45);
nonBillableTime = DateTime.Today;
nonBillableTime = nonBillableTime.AddHours(1);
nonBillableTime = nonBillableTime.AddMinutes(5);
oTimeSheetLine.Date = DateTime.Today;
oTimeSheetLine.StartTime = startTime;
oTimeSheetLine.EndTime = endTime;
oTimeSheetLine.Break = breakTime;
oTimeSheetLine.NonBillableTime = nonBillableTime;
oTimeSheetLine.ActivityType = 1;
oTimeSheetLine.CostCenter = "17005678";
oTimeSheetLine.FinancialProject = "01";
oTimeSheetLine = oTimeSheet.PM_TimeSheetLineDataCollection.Add();
startTime = DateTime.Today;
startTime = startTime.AddHours(16);
startTime = startTime.AddMinutes(30);
endTime = DateTime.Today;
endTime = endTime.AddHours(17);
endTime = endTime.AddMinutes(30);
breakTime = DateTime.Today;
breakTime = breakTime.AddMinutes(10);
nonBillableTime = DateTime.Today;
oTimeSheetLine.Date = DateTime.Today;
oTimeSheetLine.StartTime = startTime;
oTimeSheetLine.EndTime = endTime;
oTimeSheetLine.Break = breakTime;
oTimeSheetLine.NonBillableTime = nonBillableTime;
oTimeSheetLine.ActivityType = 1;
oTimeSheetLine.ServiceCall = 1;

oTimeSheetParam = oTimeSheetService.AddTimeSheet(oTimeSheet);

2. Update a Time Sheet using DI API:

SAPbobsCOM.CompanyService oCompanyService = default(SAPbobsCOM.CompanyService);
SAPbobsCOM.ProjectManagementTimeSheetService oTimeSheetService = null;
oCompanyService = oCompany.GetCompanyService();
oTimeSheetService = (SAPbobsCOM.ProjectManagementTimeSheetService)oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.ProjectManagementTimeSheetService);
SAPbobsCOM.PM_TimeSheetParams oTimeSheetParam = oTimeSheetService.GetDataInterface(SAPbobsCOM.ProjectManagementTimeSheetServiceDataInterfaces.pmtssPM_TimeSheetParams);
oTimeSheetParam.AbsEntry = 2;
SAPbobsCOM.PM_TimeSheetData oTimeSheet = oTimeSheetService.GetTimeSheet(oTimeSheetParam);
oTimeSheet.DateFrom = DateTime.Today.AddDays(-1);
oTimeSheetService.UpdateTimeSheet(oTimeSheet);

3. Delete a Time Sheet using DI API:

SAPbobsCOM.CompanyService oCompanyService = default(SAPbobsCOM.CompanyService);
SAPbobsCOM.ProjectManagementTimeSheetService oTimeSheetService = null;
oCompanyService = oCompany.GetCompanyService();
oTimeSheetService = (SAPbobsCOM.ProjectManagementTimeSheetService)oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.ProjectManagementTimeSheetService);
SAPbobsCOM.PM_TimeSheetParams oTimeSheetParam = oTimeSheetService.GetDataInterface(SAPbobsCOM.ProjectManagementTimeSheetServiceDataInterfaces.pmtssPM_TimeSheetParams);
oTimeSheetParam.AbsEntry = 2;
oTimeSheetService.DeleteTimeSheet(oTimeSheetParam);

 

4 Comments
You must be Logged on to comment or reply to a post.
  • Dear Ankit,

    Thank you for sharing the code.

    Unfortunately the objects PM_TimeSheetData and PM_TimeSheetLineData do not provide access to UDFs which can be created by default. Is anything planned on extending the API?
    By xml it doesn’t work either: “Property ‘UDF_XYZ’ of ‘PM_TimeSheetLineData’ is invalid”

    Second, the field workorder is only available for type ‘user’, not for employee, what is the reason for this limitation?

    Best regards
    Sebastian

  • Dear Mr. Sebastian Kleiner ,

    Refer to SAP Note 2777696. The issue is supposed to be fixed in SAP Business One Version 9.3 PL11. However, the decision to fix the issue can be changed without any further notice. Therefore, keep checking the mentioned SAP Note.

    For your other issue, related to field ‘Workorder’, I will check it and let you know.

    Kind regards,

    ANKIT CHAUHAN

    SAP Business One Support

  • Dear everybody,

    Do you know if there is something announced about the field Project ID and StageID of the object PM_TimeSheetLineData.

    With DI API at this moment we cannot add a time sheet with these 2 informations and it is interesting to use it in  a project management

     

    • Hi Jacques Bonnabeau,

      Refer to SAP Note 2765437  for the StageID in Time Sheet. The issue is supposed to be fixed in SAP Business One Version 9.3 PL11.

      Be advised that the time-frame is subject to change without any notice.

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support