on 04-10-2006 7:13 PM
Hi
I'm trying to use the report layout service to delete a layout, but it is always giving a error. I'm most probably doing something silly,here is the code. Please let me know if you see a problem
Try
Dim oReportLayout As SAPbobsCOM.ReportLayout
Dim oReportParam As SAPbobsCOM.ReportLayoutParams
'get report params
oReportParam = oReportLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutParams)
oReportParam.LayoutCode = "QUT20006"
'get the default layout of the specific document
oReportLayout = oReportLayoutService.GetReportLayout(oReportParam)
oReportLayout.Author = "manager"
oReportLayout.Name = "Sales Quotation_Test"
oReportLayoutService.DeleteReportLayout(oReportLayout)
sErrMsg = oCompany.GetLastErrorDescription()
If sErrMsg = Nothing Then
MsgBox("Completed succesffully")
Else
MsgBox("Error:" & sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Thanks in advance
You should use oReportParam instead of oReportLayout in the call to DeleteReportLayout.
Good luck
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error you where getting normally happens when you are passing a wrong type of argument to a function. So I just looked the function "DeleteReportLayout" definition .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I don´t know if you have it before the code you pasted or maybe is where the problem is, but you need to init the service, for example:
SAPbobsCOM.CompanyServiceClass objCompService = null;
SAPbobsCOM.ReportLayoutsService objRepoService = null;
objCompService = (SAPbobsCOM.CompanyServiceClass) this.objCompany.GetCompanyService();
objRepoService = (SAPbobsCOM.ReportLayoutsService) objCompService.GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService);
objRepoLayoutParams = (SAPbobsCOM.ReportLayoutParams) objRepoService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutParams);
objRepoLayoutParams.LayoutCode = strDocCode;
objReportLayout = (SAPbobsCOM.ReportLayout) objRepoService.GetReportLayout(objRepoLayoutParams);
etc.
if this does not help, please tell me the error you are getting to take a look.
Hope it helps,
-M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marco Antonio Blanco Freja
Thank you for answering my thread. Really appreciate it. I did declare them, here is a insert again, ive moved it to a place where you can see it.
'Global Variable
Public oCompanyService As SAPbobsCOM.CompanyService
Dim oReportLayoutService As SAPbobsCOM.ReportLayoutsService
'in procedure
try
Dim oReportLayout As SAPbobsCOM.ReportLayout
Dim oReportParam As SAPbobsCOM.ReportLayoutParams
oCompanyService = oCompany.GetCompanyService
'get report service
oReportLayoutService = oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService)
'get report params
oReportParam = oReportLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutParams)
oReportParam.LayoutCode = "QUT20006"
'get the default layout of the specific document
oReportLayout = oReportLayoutService.GetReportLayout(oReportParam)
oReportLayout.Author = "manager"
oReportLayout.Name = "Sales Quotation_Test"
oReportLayoutService.DeleteReportLayout(oReportLayout)
sErrMsg = oCompany.GetLastErrorDescription()
If sErrMsg = Nothing Then
MsgBox("Completed succesffully")
Else
MsgBox("Error:" & sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
It gives an error by oReportLayoutService.DeleteReportLayout(oReportLayout) and the error is "Specified cast is not valid". We usually get this error when something was not done correctly...i can't spot the problem. Can You???
Thanks again
Hey Louis,
Can you try using this simple section of code from the help files? Just to see if this works first
Dim oCmpSrv As SAPbobsCOM.CompanyService
Dim oReportLayoutService As ReportLayoutsService
Dim oReportLayout As ReportLayout
Dim oReportParam As ReportParams
'get company service
oCmpSrv = oCompany.GetCompanyService
'get report layout service
oReportLayoutService = oCmpSrv.GetBusinessService(ServiceTypes.ReportLayoutsService)
'get report params
oReportParam = oReportLayoutService.GetDataInterface(ReportLayoutsServiceDataInterfaces.rlsdiReportParams)
'report code is the document type code (POR2=PurchaseOrder)
oReportParam.ReportCode = "POR2"
'get the default layout of the specific document
oReportLayout = oReportLayoutService.GetDefaultReportLayout(oReportParam)
'set the new layout name
oReportLayout.Name = "My Layout"
'set the new author name
oReportLayout.Author = "My Author"
'REPLACE THIS LINE WITH DELETE
oReportLayoutService.AddReportLayout(oReportLayout)
Thanks Jose, you were spot on.
But how do you know when to use "oReportLayout" or "oReportParam" in the brackets of "oReportLayoutService.DeleteReportLayout(oReportParam)"?? If you look at the example that curtis place they do it the way i had it, but now for deleting it's the other way. Why???
Thank you too Curtis for attemting. The adding of documents works if i remember correctly.
Thanks to both of you again
User | Count |
---|---|
99 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.