on 04-20-2018 1:57 PM
Hi everybody,
We are using SAP B1 9.2 PL08 and we have a macro done in vba (excel) to interact with sap using DI API (sapbobscom). It works well. Now I would like to use the TimeSheet object to register user's time. I found an example on the web (https://blogs.sap.com/2017/08/01/time-sheet-in-sap-business-one-sdk/) and try to translate into vba, wihout success.
Hereafter my code :
Dim oCompanyService As SAPbobsCOM.CompanyService
Dim oTimeSheetService As SAPbobsCOM.ProjectManagementTimeSheetService
Dim oTimeSheet As SAPbobsCOM.PM_TimeSheetData
Dim oTimeSheetLine As SAPbobsCOM.PM_TimeSheetLineData
Dim oTimeSheetParam As SAPbobsCOM.PM_TimeSheetParams
Dim StartTime As Date
Dim EndTime As Date
Dim breakTime As Date
Dim NonBillableTime As Date
ConnectionSQLSAPOpen
Set oCompanyService = oCompanySAP.GetCompanyService
Set oTimeSheetService = oCompanyService.GetBusinessService(ProjectManagementTimeSheetService)
Set oTimeSheet = oTimeSheetService.GetDataInterface(pmtssPM_TimeSheetData)
Set oTimeSheetLine = oTimeSheetService.GetDataInterface(pmtssPM_TimeSheetLineData)
Set oTimeSheetParam = oTimeSheetService.GetDataInterface(pmtssPM_TimeSheetParams)
oTimeSheet.TimeSheetType = SAPbobsCOM.TimeSheetTypeEnum.tsh_Employee
oTimeSheet.UserId = 2
StartTime = VBA.DateAdd("h", 7, VBA.Int(Now)) 'start a 7.00
EndTime = VBA.DateAdd("n", 90, StartTime) 'add 90 minutes
breakTime = VBA.DateAdd("n", 45, VBA.Int(Now)) 'pause 45 minutes
NonBillableTime = VBA.DateAdd("n", 15, VBA.Int(Now))
oTimeSheetLine.Date = Now
oTimeSheetLine.StartTime = StartTime
oTimeSheetLine.EndTime = EndTime
oTimeSheetLine.Break = breakTime
oTimeSheetLine.NonBillableTime = NonBillableTime
oTimeSheetLine.ActivityType = 1
oTimeSheetLine.CostCenter = ""
oTimeSheetLine.FinancialProject = "090"
oTimeSheetLine = oTimeSheet.PM_TimeSheetLineDataCollection.Add()
oTimeSheetParam = oTimeSheetService.AddTimeSheet(oTimeSheet)
ConnectionSQLSAPClose
We program stops at 'oTimeSheetLine = oTimeSheet.PM_TimeSheetLineDataCollection.Add()'.
Could you please help me ?
Kind regards
In lieu of the first Set oTimesheetLine statement, put what you had at the end, except use the "Set" keyword instead:
Set oTimeSheetLine = oTimeSheet.PM_TimeSheetLineDataCollection.Add()
Also make sure to use the "Set" keyword with the call to AddTimeSheet:
Set oTimeSheetParam = oTimeSheetService.AddTimeSheet(oTimeSheet)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
3 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.