cancel
Showing results for 
Search instead for 
Did you mean: 

JCO sap b1 how to pass parameters to GeneralService

0 Kudos

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

View Entire Topic
0 Kudos

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

former_member185682
Active Contributor
0 Kudos

Hi Giu,

If you have installed the Sap Business One SDK on your machine, inside of installation folder/Help/ there is a zip file called JCO. Unzip this and you see the documentation. Unfortunately there is no sample code in this documentation.

Hope it helps.

Kind Regards,

Diego Lother