Dynamics 365 Business Central: native support for barcodes

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… 😉

8 Comments

  1. Didn’t make it, and I have double checked twice every single step. Are you sure this is still running fine in v18? Could you try and confirm it is still working fine? Thank you.

    Liked by 1 person

      1. report 50100 ItemLabelTest
        {
        UsageCategory = Administration;
        ApplicationArea = All;
        DefaultLayout = RDLC;
        UseRequestPage = false;
        RDLCLayout = ‘ItemLabelTest.rdl’;

        dataset
        {
        dataitem(Item; Item)
        {
        column(No_Item; “No.”)
        {
        }
        column(Description_Item; Description)
        {
        }
        column(GTIN_Bar; EncodedText)
        {
        }

        trigger OnAfterGetRecord()
        var
        barcodesymbology: enum “Barcode Symbology”;
        barcodefontprovider: Interface “Barcode Font Provider”;
        BarcodeString: Text;
        begin
        if Item.GTIN = ” then exit;
        barcodefontprovider := Enum::”Barcode Font Provider”::IDAutomation1D;
        barcodesymbology := barcodesymbology::Code39;
        BarcodeString := item.GTIN;
        barcodefontprovider.ValidateInput(BarcodeString, barcodesymbology);
        EncodedText := barcodefontprovider.EncodeFont(BarcodeString, barcodesymbology);
        end;
        }
        }

        And in the RDLC layout, I have marked the field GTIN_Bar with font:
        IDAutomationSHC39XL Demo

        which I installed from the demo pack that shows in some official link of MS.

        Liked by 1 person

  2. Currently when I try this solution I get this in my barcode fields: Í5RÈ2sÎ and ÍÂt-A*ÂÂ#{ÉÎ On the report I have selected the correct Font. Is there anything else that we need to do to get this to work?

    Like

Leave a Reply to frankmnielsen Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.