11-09-2016 1:51 PM - edited 02-03-2024 6:18 PM
Hallo,
I'm developing an application with JCO java connetor for sap b1. I need to load an UDO, but I don't know how to set my parameters on the general service, in order to load a sepcific record.
On the help center I found this example in VB:
sCmp = oCompany.GetCompanyService
'Get a handle to the SM_MOR UDO
oGeneralService = sCmp.GetGeneralService("SM_MOR")
'Get UDO record
oGeneralParams = oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)
oGeneralParams.SetProperty("DocEntry", "2")
oGeneralData = oGeneralService.GetByParams(oGeneralParams)
So I tried to write the same code in java:
IGeneralService generalService = company.getCompanyService().getGeneralService("MY_UDO");
IGeneralDataParams generalParams = (IGeneralDataParams)generalService.getDataInterface(SBOCOMConstants.GeneralServiceDataInterfaces_gsGeneralDataParams);
...
but it gives me a class cast exception:
ClassCastException: Cannot cast com.sap.smb.sbo.wrapper.com.Dispatch to com.sap.smb.sbo.api.IGeneralDataParams
So my question is, how can I build an IGeneralDataParams, in order to pass parameters to generalService.getByParams(...)?
Thanks
Giu
Ok, it's not really clear to me but I think it's a library bug... or meabe I miss something. I decompiled GeneralData.getProperty and this is the code:
public Object getProperty(String paramString){
Variant localVariant = Dispatch.call(this.m_GeneralData, "GetProperty", paramString);
return localVariant.getObject();
}
The error is thrown when is called the native method
localVariant.getObject();
I noted that Variant has also other methods to convert the object in a specific type:
getBoolean(), getString(), getInt() etc...
So I tried to replicate the same code using the specific convertion method like this:
Variant myVariant = Dispatch.call(data.retrieveRawGeneralData(), "GetProperty", "DocKey");
myVariant.getInt();
And I noted that using these methods it works!!!
So, I don't know if this is the right solution, but it works. The only annoing thing is that I have to choose the right method to call according to the expected data type.
P.S.
It would be very nice to have a documentation with some code example for JCO sdk from SAP.
SAP Business One SDK Help Center is usefull, but java is not vb. I know this library is just a wrapper but sometimes a more specific documentation would be better.
Giu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
105 | |
9 | |
7 | |
6 | |
5 | |
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.