Skip to Content
0
Former Member
Mar 17, 2017 at 02:55 PM

SAP Business One DI API (Java) - How to add a Blanket Agreement

775 Views Last edit Mar 17, 2017 at 02:57 PM 3 rev

Hello, this is my first post here.

I need to create and add a Blanket Agreement using the Java DI API.

I am able to update an existing Blanket Agreement using the following code:

com.sap.smb.sbo.api.BlanketAgreementsService BAService = (com.sap.smb.sbo.api.BlanketAgreementsService) com.sap.smb.sbo.api.SBOCOMUtil.newBlanketAgreementsService(company.getCompanyService());
BlanketAgreementsParams BAParams = (BlanketAgreementsParams) BAService.getBlanketAgreementList();
BlanketAgreementParams  BAParam =  (BlanketAgreementParams) BAParams.add();


// Suppose I want to update the Blanket Agreement number 350
BAParam.setAgreementNo(350); 


IBlanketAgreement BA;
BA = (IBlanketAgreement) BAService.getBlanketAgreement(BAParam);


// Exemple
BA.setBPCode(myBP.getBPCode());
BA.setDescription(myBP.getDescription());
//...


 BAService.updateBlanketAgreement(BA);

But what I really want to do now is to add a new Blanket Agreement.

I can't find any Java example for doing this and I am having no success to declare a new Blanket Agreement object.

I tried many things, like the following code for example:

com.sap.smb.sbo.api.BlanketAgreementsService BAService = (com.sap.smb.sbo.api.BlanketAgreementsService) com.sap.smb.sbo.api.SBOCOMUtil.newBlanketAgreementsService(company.getCompanyService());
BlanketAgreementsParams BAParams = (BlanketAgreementsParams) BAService.getBlanketAgreementList();
BlanketAgreementParams  BAParam =  (BlanketAgreementParams) BAParams.add();




IBlanketAgreement BA;
BA = (IBlanketAgreement) myBPSInicio.getDataInterface(SBOCOMConstants.BlanketAgreementsServiceDataInterfaces_basBlanketAgreement);
// I also tried BA = (com.sap.smb.sbo.api.BlanketAgreement) myBPSInicio.getDataInterface(SBOCOMConstants.BlanketAgreementsServiceDataInterfaces_basBlanketAgreement);

With this code I get an exception:

java.lang.ClassCastException: com.sap.smb.sbo.wrapper.com.Dispatch cannot be cast to com.sap.smb.sbo.api.BlanketAgreement

Can someone teach me how to declare and add a new Blanket Agreement Object using the DI API and Java?

Thanks!