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();

   super();
}

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()
{
   MyBarCode.string(true,InventTable.ItemId);
   MyBarCode.encode();

   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.

15 comments:

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

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

    ReplyDelete
  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" (http://msdn.microsoft.com/en-US/library/aa889472.aspx). I fully agree with mp.

    ReplyDelete
  4. Hi all,

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

    Willy

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

    Thanks

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

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

    ReplyDelete
  7. convert number to str
    BarCode.string(true,Num2str(qtyCalc,0,2,1,3));

    ReplyDelete
  8. How do i get Txt under the barcode ?

    ReplyDelete
  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

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

    Ax 2012 Development and Coding

    ReplyDelete
  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

    ReplyDelete
  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.

    ReplyDelete
    Replies
    1. Hi Vishal.

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

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

    ReplyDelete
  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.:
    http://ax.docentric.com/barcodes-microsoft-dynamics-ax/

    ReplyDelete