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.
Installation
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:
C:\Windows\Fonts
In case you don’t have this font, you can download BC C39 3 to 1 HD font.zip. It includes three versions:
- BC C39 3 to 1 HD Narrow
- BC C39 3 to 1 HD Medium
- 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.
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); barcode.encode(); 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:
Testing
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.
Troubleshooting
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.
For those of you who need to print barcodes in AX 2012, I found a post by Sreenath Reddy which I’d like to share. The process differs significantly in AX 2012 because the reporting platform has transitioned to SSRS.
Here’s the link:
http://dynamicsaxgyan.wordpress.com/2012/05/15/display-barcode-in-ssrs-report-dynamics-ax-2012/
LikeLike
Hi Ashok,
Your posts are really helpful.
Keep up the good work and keep posting!
// Nikunj
LikeLike