Printing barcodes in Microsoft Dynamics AX 2009

This post demonstrates how to display data as a barcode within a report. Code sample and barcode font are included.

To keep things simple, the following design choices will apply:

  • Barcodes will be displayed using Code 39 specification. For more information on encoding and supported characters, refer to Code 39 from Wikipedia.
  • A very simple report is provided to display Payment terms. The PaymTerm.PaymTermId field and its barcode format are shown on the report.


Barcode font

The workstation where barcodes will be printed must have the appropriate font installed. In our example, we’ll be using BC C39 3 to 1 HD font. The exact installation location for the font might vary by operating system, but it usually can be found at:


In case you don’t have this font, you can download BC C39 3 to 1 HD It includes three versions:

  1. BC C39 3 to 1 HD Narrow
  2. BC C39 3 to 1 HD Medium
  3. BC C39 3 to 1 HD Wide

Code sample

Import Report_SampleBarcodeReport.xpo into your Dynamics AX 2009 test instance and then open it from the AOT.

AOT > Reports > SampleBarcodeReport

There are a couple things to note. First, the barCode() method encodes the field’s data (PaymTermId) in the proper format.

//BP Deviation documented
display BarCodeString barCode()
    Barcode barcode;

    barcode = Barcode::construct(BarcodeType::Code39);
    barcode.string(true, PaymTerm_1.PaymTermId);

    return barcode.barcodeStr();

Second, some properties are set on the Barcode string control.

Run the report and send the output to the screen. It should look similar to this:


Generate a test barcode for comparison. You can use a free online barcode generator to produce a sample barcode with the data you specify. For this example, let’s generate a Code 39 barcode for the value “COD”.

Compare the sample with the corresponding barcode from your report. They should be the same.

You can also verify that the barcode font is properly installed on your workstation by using Microsoft Word. Create a Word document with test data “COD”.

Notice that leading and trailing asterisks surround the test data value. This is a requirement of the Code 39 specification. However, note that you do NOT need to provide these asterisks when supplying data for the barcode field within your AX report. Those characters will be added automatically by the barCode() method.


Printing barcodes is fairly simple as you can see, but there are some pitfalls. If you’re producing barcodes which fail to scan properly, try the following suggestions.

Confirm that your barcode scanner is working properly.

First, confirm that your scanner is capable of reading the barcode type you’ve selected (e.g. Code 39) and make sure that it’s properly configured. You should test the scanner using a barcode of the same type that was produced by a source other than your report.

Adjust white space before and after the barcode.

If there is no white space before or after the barcode, it might not scan properly. Make sure that there is at least 1/4 inch of white space on either side of the barcode.

Increase the barcode field length.

Sometimes the field displaying the barcode is not wide enough in the report designer. This can happen either when the Width property is set to Auto or even when it’s manually specified. Try expanding the field as necessary to prevent the barcode from being distorted due to compression.

Use a wider version of the barcode font.

Some scanners have difficulty reading the narrow version of a barcode font. Try using a medium or wide version instead.

2 thoughts on “Printing barcodes in Microsoft Dynamics AX 2009

Leave a Reply

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

You are commenting using your 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.