Skip to Content

Hi,

I worked with java program using “sboapi.jar” & “sbowrapper.jar” for approval of SAP Business One pending documents

 

kindly make sure of enable “Activate Approval Procedures in DI”  under “General Settings”

 

Please find the below source code

 

 

public static void main(String args[]) {

ApprovalRequestsService oApprovalRequestsService = null;
ApprovalRequestsParams oApprovalRequestsParams = null;
ApprovalRequestParams oApprovalRequestParams = null;

ApprovalRequest oApprovalRequest = null;
ApprovalRequestDecision oApprovalRequestDecision = null;

ICompany company;
IDocuments pedido;
SBOCOMUtil util = new SBOCOMUtil();
company = util.newCompany();
try {
company.setServer(“mserver”);
company.setCompanyDB(“Test3”);
company.setUserName(“manager”);
company.setPassword(“1234567”);
company.setDbServerType(SBOCOMConstants.BoDataServerTypes_dst_MSSQL2008);
company.setLanguage(com.sap.smb.sbo.api.SBOCOMConstants.BoSuppLangs_ln_English);
company.setDbUserName(“sa”);
company.setDbPassword(“s111”);
company.setUseTrusted(new Boolean(false));
company.setLicenseServer(“mserver:40000”);
int result = company.connect();
System.out.println(“Company: ” + company.getCompanyName());
// analize connection result
if (result != 0) {
System.out.println(“Connection error: ” + result);
} else {

Object oApprovalRequestsServiceObject = company.getCompanyService()
.getBusinessService(SBOCOMConstants.ServiceTypes_ApprovalRequestsService);

IApprovalRequestsService oApprovalRequestsServiceInterface = new ApprovalRequestsService(
oApprovalRequestsServiceObject);

Object oApprovalRequestsService_GetDataInterface = oApprovalRequestsServiceInterface.getDataInterface(
SBOCOMConstants.ApprovalRequestsServiceDataInterfaces_arsApprovalRequestsParams);
IApprovalRequestsParams oApprovalRequestsParamsInterface = new ApprovalRequestsParams(
oApprovalRequestsService_GetDataInterface);

oApprovalRequestsParamsInterface = oApprovalRequestsServiceInterface.getOpenApprovalRequestList();

Variant myVariant = Dispatch.call(oApprovalRequestsParamsInterface.retrieveRawApprovalRequestsParams(),
“Count”);
myVariant.getInt();

System.out.println(“Count : ” + myVariant.getInt());

myVariant = Dispatch.call(oApprovalRequestsParamsInterface.retrieveRawApprovalRequestsParams(), “Item”,
myVariant.getInt() – 1);
IApprovalRequestParams oApprovalRequestParamsInterface = new ApprovalRequestParams(
myVariant.getObject());

oApprovalRequestParamsInterface.setCode(3);
//myVariant = Dispatch.call(oApprovalRequestParamsInterface,”Code”);
System.out.println(“Code : ” + oApprovalRequestParamsInterface.getCode());
IApprovalRequest oApprovalRequestInterface = oApprovalRequestsServiceInterface
.getApprovalRequest(oApprovalRequestParamsInterface);

myVariant = Dispatch.call(oApprovalRequestInterface.retrieveRawApprovalRequest(),
“ApprovalRequestDecisions”);
ApprovalRequestDecisions oApprovalRequestDecisions = new ApprovalRequestDecisions(
myVariant.getObject());
oApprovalRequestDecisions.add();

oApprovalRequestDecisions.item(0).setRemarks(“Approve”);
oApprovalRequestDecisions.item(0).setStatus(SBOCOMConstants.BoApprovalRequestDecisionEnum_ardApproved);

oApprovalRequestsServiceInterface.updateRequest(oApprovalRequestInterface);

System.out.println(“Connection success, company name: ” + company.getCompanyName());
pedido = util.newDocuments(company, new Integer(22));

if (pedido.getByKey(new Integer(286))) {
System.out.println(“Pedido recuperado.” + pedido.getDocEntry());
} else {
System.out.println(“Error al reuperar” + company.getLastErrorCode() + ” – ”
+ company.getLastErrorDescription());
}
}
} catch (SBOCOMException ex) {
System.out.println(ex.getStackTraceString());
} finally {
company.disconnect();
}

}

 

 

//oApprovalRequestParamsInterface.setCode(3);

OWDD.DocEntry for setCode

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply