ER has a built-in function to display different types of barcodes. It’s quite simple to use and works great for printing labels and other types of documents.
I’ll show an example where a barcode needs to be printed. This barcode could be Ean13, Code128, or blank.
Model and Mapping
While this step isn’t strictly necessary in most cases, since we probably already have a barcode number in the format and know exactly what type of barcode we need, it will help us understand more complex developments.
Let’s start with the model, we only have three fields: the variant (string), the barcode (string), and the type (Model Enum: EAN13, Code128, or Other).

In the mapping, we start with a user input parameter, which is the RecId of the InventItemBarcode
. Naturally, we can’t expect the user to manually input a RecId, but we can pass this variable through code if we integrate the report into a form. While this is beyond the scope of this guide, you can learn how to do it here. We also need to declare BarCodeType
, which is an AOT Enum, then the enum we created in the model BCTypeModel
, and the table records from InventItemBarCode
.

Next, we bind the three model fields. The only complexity lies in the Type
field. From the InventItemBarCode
table, we navigate to a related table, BarCodeSetup
. We use this value in a case formula: if the case type is the AOT Enum value Ean13
, we return the Model Enum type EAN13
; if the case type is the AOT Enum value Code128
, we return the Model Enum type Code128
. In all other cases, we return the Model Enum type Other
.

Format
Let’s start with a Word template (if it’s completely blank, it may cause problems).

And create a format of type Word:

In the format designer, add an Excel root (it’s the same for both Excel and Word), and upload our template in attachments.

We’ll create three cells and link the variant name and barcode number.

Now, create the barcodes inside a container. We’ll create three, starting with “Blank.” For this one, we won’t actually create a barcode but will use a blank image in base64.

Now, we can create the EAN13 barcode:

Select the barcode format ‘EAN-13’. If you want to display the code string below the barcode, you can check ‘Output content’. However, I usually don’t select it because I often get feedback that it’s too small, so I add it manually. You’ll also need to set the height, width, and margin. It probably won’t be perfect the first time, but we can adjust it through trial and error.

Now, we’ll do the same for Code-128 and also declare the model enum in the same container.

Finally, we can complete our last empty format node with the following formula:
CASE
(
model.Type,
BarCodes.barCodeTypeModel.Code128, BarCodes.Code128(model.BarCode)
BarCodes.barCodeTypeModel.EAN13, BarCodes.Ean13(model.BarCode)
BarCodes.Blank
)
It’s a very similar case formula to the one used in the mapping. Parameters 3 and 5 are the barcodes. As you can see, we need to pass the barcode code as a parameter. Parameter 6 is the default value, which is a blank image.
Now, let’s save, download the Word file, and add the fields, making sure the ‘Developer’ tab is enabled in Word.



We insert the variant name and the barcode number as plain text, and the barcode as a picture:


Now, upload the template again after deleting the old one and selecting the new one in the “Template” field.

Finally, we can try it out with ‘Run’ using a RecId from [environment]/?cmp=[dataArea]&mi=SystableBrowser&tablename=InventItemBarcode:


Leave a Reply