Skip to Content
Product Information

Setting Up Holidays Using SAP Business One DI API

In SAP Business One, you can setup the Holidays for an specific year and make sure that it is aligned with your business policy. It allows you to define whether or not count weekend days as business days when calculating due dates. Also, while running the MRP wizard you can define whether to consider the holiday dates for production items and/or purchase items.

The Holiday Dates window can be accessed from the “Holidays” field in the Administration → System Initialization → Company Details → Accounting Data tab.

Holidays in SAP Business One DI API:

Starting from Feature Package 2011 for SAP Business One, the object for Holidays is exposed as a Service Type object i.e. HolidayService.

Here is how to use the HolidayService object in SAP Business One DI API:

  • Add a Holiday using DI API:
SAPbobsCOM.CompanyService oCompanyService = oCompany.GetCompanyService();
SAPbobsCOM.HolidayService oHolidayService = oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.HolidayService);
SAPbobsCOM.Holiday oHoliday = oHolidayService.GetDataInterface(SAPbobsCOM.HolidayServiceDataInterfaces.hsHoliday);
oHoliday.HolidayCode = "HLD2021";
oHoliday.WeekNoRule = SAPbobsCOM.BoWeekNoRuleEnum.fromJanFirst;
oHoliday.WeekendFrom = SAPbobsCOM.BoWeekEnum.Saturday;
oHoliday.WeekendTO = SAPbobsCOM.BoWeekEnum.Sunday;
oHoliday.ValidForOneYearOnly = SAPbobsCOM.BoYesNoEnum.tYES;
oHoliday.SetWeekendsAsWorkDays = "N";
SAPbobsCOM.HolidayDate oHolidayDate = oHoliday.HolidayDates.Add();
oHolidayDate.StartDate = new DateTime(2021,08,15);
oHolidayDate.EndDate = new DateTime(2021,08,15);
oHolidayDate.Remarks = "Independence Day";
oHolidayService.AddHoliday(oHoliday);
  • Update a Holiday using DI API:
SAPbobsCOM.CompanyService oCompanyService = oCompany.GetCompanyService();
SAPbobsCOM.HolidayService oHolidayService = oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.HolidayService);
SAPbobsCOM.HolidayParams oHolidayParams = oHolidayService.GetDataInterface(SAPbobsCOM.HolidayServiceDataInterfaces.hsHolidayParams);
oHolidayParams.HolidayCode = "HLD2021";
SAPbobsCOM.Holiday oHoliday = oHolidayService.GetHoliday(oHolidayParams);
SAPbobsCOM.HolidayDate oHolidayDate = oHoliday.HolidayDates.Add();
oHolidayDate.StartDate = new DateTime(2021,01,26);
oHolidayDate.EndDate = new DateTime(2021,01,26);
oHolidayDate.Remarks = "Republic Day";
oHolidayService.UpdateHoliday(oHoliday);
  • Delete a Holiday using DI API:
SAPbobsCOM.CompanyService oCompanyService = oCompany.GetCompanyService();
SAPbobsCOM.HolidayService oHolidayService = oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.HolidayService);
SAPbobsCOM.HolidayParams oHolidayParams = oHolidayService.GetDataInterface(SAPbobsCOM.HolidayServiceDataInterfaces.hsHolidayParams);
oHolidayParams.HolidayCode = "HLD2021";
oHolidayService.DeleteHoliday(oHolidayParams);
Be the first to leave a comment
You must be Logged on to comment or reply to a post.