When working with an ERP, using barcodes on different reports is a common practice and I think that every ERP should natively support using and printing barcodes (and QR codes too).
Using barcodes with Dynamics 365 Business Central was quite easy in an on-premise environment (just install a font and you’re ready to go) but not so easy to handle on a SaaS environment, where you were not able to install custom fonts and you were often forced to rely on external services.
Now things changes! With Dynamics 365 Business Central 2021 Wave 1 (v18) you have native support for barcodes on reports. The functionality is provided by the Barcode module of the System Application. The module includes the objects and tools that you need to add barcodes to your reports.
Using barcodes on reports is actually very easy. Just:
- Declare a Barcode Font Provider (as default Dynamics 365 Business Central online comes equipped with a barcode provider and fonts from IDAutomation).
- Select the barcode you want to use.
- (OPTIONAL) Validate the input string that you want to print on your barcodes.
- Encode the string and display it on your report.
To explain how to do that, here’s a quick example. This report prints a “label” for items, by showing No. and Description fields in clear text and then a barcode with the item’s number encoded:
I think that the code is quite self explanatory.
I’ve declared a Barcode Font Provider by using the “Barcode Font Provider” interface and the relative enum. As default, on Dynamics 365 Business Central online you have only one provider enabled (IDAutomation1D) but if you want you can also create your own provider by extending the enum and then providing your own interface implementation. Then, with the “Barcode Symbology” enum you can declare the type of barcode you want to use (a complete list of supported barcodes types is available here).
I’ve then used the BarcodeFontProvider.ValidateInput method in order to have a validation of the barcode string. If this string contains characters that are not supported by your barcode font, an error is thrown. If all is ok, then you can call the BarcodeFontProvider.EncodeFont method (passing the string to encode and the type of barcode to render) in order to have the encoded string. Very easy…
Now just create your layout, publish the report and… voilà:
You’ve your barcode displayed. No font installed, no external service called… all is natively supported (fonts are automatically installed on the online instance when provisioned).
NOTE: when you design the report layout, to have the barcode font correctly selected you need to:
- Install the IDAutomation fonts (demo) on your dev machine OR
- Set the font ID (name) of your barcode field with the font id from IDAutomation:
Reember that if instead you’re working with Dynamics 365 Business Central on-premise, you need to install the barcode fonts on the service tier and then reboot the machine.
Happy barcoding… 😉