Product Information
Using Bar Codes in SAP Business One SDK
Bar Codes:
A barcode is an optical, machine-readable, representation of data; the data usually describes something about the object that carries the barcode.
In SAP Business One, you can use the Bar Codes window (Inventory → Bar Codes) to define Bar Codes for your items. Multiple bar codes are allowed for each single UoM of an item.
For more information on Bar Codes in SAP Business One, you can refer to following link:
Using Bar Code in SAP Business One SDK:
Bar Code is exposed a Service Type Object (BarCodesService) in SAP Business One SDK. You can use it following ways using DI API:
Create a Bar Code for an Item using DI API:
SAPbobsCOM.ICompanyService oCompanyService = (SAPbobsCOM.ICompanyService)oCompany.GetCompanyService();
SAPbobsCOM.BarCodesService oBarCodesService = (SAPbobsCOM.BarCodesService)oCompanyService.GetBusinessServiceSAPbobsCOM.ServiceTypes.BarCodesService);
SAPbobsCOM.BarCode oBarCode = (SAPbobsCOM.BarCode)oBarCodesService.GetDataInterface(BarCodesServiceDataInterfaces.bsBarCode);
SAPbobsCOM.BarCodeParams oBarCodeParams;
oBarCode.ItemNo = "A00002";
oBarCode.BarCode = "BA0002";
oBarCode.FreeText = "BarCode creation Using DI API";
oBarCode.UoMEntry = 3; //You need to provide 'UomEntry' from 'OUOM' table.
oBarCodesService.Add(oBarCode);
Update a Bar Code for an Item using DI API:
SAPbobsCOM.ICompanyService oCompanyService = (SAPbobsCOM.ICompanyService)oCompany.GetCompanyService();
SAPbobsCOM.BarCodesService oBarCodesService = (SAPbobsCOM.BarCodesService)oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.BarCodesService);
SAPbobsCOM.BarCode oBarCode = (SAPbobsCOM.BarCode)oBarCodesService.GetDataInterface(BarCodesServiceDataInterfaces.bsBarCode);
SAPbobsCOM.BarCodeParams oBarCodeParams;
oBarCodeParams = (SAPbobsCOM.BarCodeParams)oBarCodesService.GetDataInterface(BarCodesServiceDataInterfaces.bsBarCodeParams);
oBarCode = (SAPbobsCOM.BarCode)oBarCodesService.GetDataInterface(BarCodesServiceDataInterfaces.bsBarCode);
oBarCodeParams.AbsEntry = 11;
oBarCode = oBarCodesService.Get(oBarCodeParams);
oBarCode.ItemNo = "A00002";
oBarCode.BarCode = "BA0002";
oBarCode.UoMEntry = 3; //You need to provide 'UomEntry' from 'OUOM' table.
oBarCode.FreeText = "";
oBarCodesService.Update(oBarCode);
Delete a Bar Code using DI API:
SAPbobsCOM.ICompanyService oCompanyService = (SAPbobsCOM.ICompanyService)oCompany.GetCompanyService();
SAPbobsCOM.BarCodesService oBarCodesService = (SAPbobsCOM.BarCodesService)oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.BarCodesService);
SAPbobsCOM.BarCode oBarCode = (SAPbobsCOM.BarCode)oBarCodesService.GetDataInterface(BarCodesServiceDataInterfaces.bsBarCode);
SAPbobsCOM.BarCodeParams oBarCodeParams;
oBarCodeParams = (SAPbobsCOM.BarCodeParams)oBarCodesService.GetDataInterface(BarCodesServiceDataInterfaces.bsBarCodeParams);
oBarCode = (SAPbobsCOM.BarCode)oBarCodesService.GetDataInterface(BarCodesServiceDataInterfaces.bsBarCode);
oBarCodeParams.AbsEntry = 11; //You need to provide 'BcdEntry' from 'OBCD' table.
oBarCodesService.Delete(oBarCodeParams);
Thanks for the code although I can implement it, I have some doubts What is the function of SAPbobsCOM.BarCodeParams oBarCodeParams in Add fuction?.
Hi Uriel,
BarCodeParams holds the key to an existing bar code. This object is used to pass keys to and retrieve keys from BarCodesService methods.
Although , it is not being used in Add method above.
Kind regards,
ANKIT CHAUHAN
SAP SME Support
Thanks ANKIT CHAUHAN
Mr. Ankit Chauhan the example you are presenting here is not working for me! I have no idea why and i'm trying to figure that out. I was wondering if you have a manual or a link where i can access the manual you used for this example.
Hi Uriel,
The provided sample is working for me in a DEMO Database on SAP Business One Version 9.2 PL07. The purpose of this post was to make it available for the partners/customers/SAP Users because it is not included in the SDK Help Center.
Hopefully, it will be included soon in the SDK Help. Meanwhile, could you please try to post your sample code and the error message that you are getting?
Kind regards,
ANKIT CHAUHAN
SAP SME Support
Hi ANKIt
The sample not work for me, the problem is my version SAP. the sample dont working in SAP 9.1 PL11
This line does not work: SAPbobsCOM.ICompanyService oCompanyService = (SAPbobsCOM.ICompanyService)oCompany.GetCompanyService();
Change line code for: SAPbobsCOM.CompanyService oCompanyService = aSAP.CoEmpresa.GetCompanyService();
Hi Uriel,
Definitely, a problem with your code only. It is working for me on SAP Business One Version 9.1 PL11.
Would recommend you to go through with your code again.
Kind regards,
ANKIT CHAUHAN
SAP SME Support
Is it not possible to add several barcodes for the item through the DI API using READXML function of OITM XML template?(with detailed OBCD tag)
It is working fine on items with several UOM, but not for Item with "manual" UOM...
the problem is that no error is returned from the DI API, but the final result is that the barcode is not added or that the previous barcodes are deleted and the new one is added.
Hi Michal Cohen,
It seems that you are having the same scenario as mentioned in SAP Note 2841962.
Therefore, I would ask you to test the issue in the SAP Business One Version 9.3 PL12 and let us know the results.
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
Thanks for the fast reply!!
I will check in pl 12