Saturday, May 15, 2010

How to use barcodes in your Ax report - Part 2/2

In part 2 of the barcode posts (read part 1 here), we'll have a look at another barcode type.
We gonna see how to use barcodes of type Code 128 in your report. This is a high density barcode type, with checksum digit, supporting alphanumeric symbols. Very commonly used.

We gonna use the same example as in the previous post, an inventory report, with InventTable as the datasource.

We'll start off with our class declaration.
In this, we'll create an object for class BarcodeCode128. This class is used for encoding the barcode, checking/calculating check digit.

public class ReportRun extends ObjectRun
   BarcodeCode128 MyBarcode;
In the init method of our report, we instantiate the class.

public void init()
{  ;
   MyBarcode= BarcodeCode128::construct();


As opposed to Code 39 (see previous post), we now have to do some actual encoding. But no worries, the barcode class does this for us.
We'll create our display method in which we'll do the encoding:

Display BarcodeStr ShowBarcode()

   return MyBarCode.barcodeStr();
Remember to set the report control properties with the appropriate font, something like this:

And this is what your result looks like when you call the report.

As you can see from the other classes in the AOT named Barcode*, Ax supports barcodes of type EAN, Interleaved 2 of 5, UPC, ...

Tip: This website, a site by Russ Adams, has some real good info on barcodes.


  1. Display str ShowBarcode()
    should read
    Display BarCodeString ShowBarcode()

  2. That Shouldn't be a problem....
    BarCodeString is a string datatype....

  3. Not a practical problem at first glance, but a really bad practice to use str. BarCodeString is limited to 70 chars as an EDT. The type "str" is "unlimited" ( I fully agree with mp.

  4. Hi all,

    As this appears to be a hot topic, I've applied the EDT. Now fully according to best practice :-)


  5. Hi,
    How to print 2D (matrix) barcode with Dynamics ax 2009??
    can you help me


  6. what if i want to print barcode for a real type field?

    for example: Table: ProdTable, Fieldname: qtycalc
    can anyone help me?

  7. convert number to str

  8. How do i get Txt under the barcode ?

  9. This is axapta ERP blog for Technical and functional fields and includes Microsoft Dynamics Axapta tutorials and Dynamics Axapta Coverage. This blog also contains x++ code help for Ax developer and solution of technical and functional daily issues. This blog is specific for Microsoft dynamics programming. Enterprise portal, SharePoint services, business connectors and Enterprise Resource Planning applications and sql database.It will help to get Microsoft Business Solutions.

    axapta ERP blog

  10. Nice post. You can visit following link to get Ax 2012 technical code and error solutions

    Ax 2012 Development and Coding

  11. Hi
    Can anyone help me how can I enable the barcode field in the transaction windows? I have created 2 variants for one item based on the color and size dimensions.

    Thanks in advance

  12. Hi, I am facing an issue where barcode machine is not reading "_"(underscore) character. Is it something to do with handgun or barcode type i am using. I am using code 39 and code 128 for this.

    1. Hi Vishal.

      I am also facing this issue. Did you find a solution for this?
      //Richard Hellstenius

  13. Hi Vishal, have you solved the problem with de underscore? I have the same problem.

  14. Cool article! This one also was helpful for me to understand how printing barcodes works in AX, why we actually need Barcode classes, how to print 2D barcodes in AX, etc.: