Barcode
Codeunit 5523960 bdev.Barcode is the entry point of the app. It encodes a value as a barcode image, reads a barcode back out of an image, and builds a vCard barcode from a contact.
Code
Every method returns or takes the image as a Temp Blob codeunit, which is what a Media or Blob field, a report item and a file download all accept.
Encode(Enum, Text)
Encodes a value in a symbology, with the default appearance.
Code
| Parameter | Type | Description |
|---|---|---|
barcodeSymbology | Enum "bdev.Barcode Symbology" | The symbology, for example QR Code or Code 128. |
value | Text | The value to encode. |
Returns the barcode image as a Temp Blob codeunit.
The defaults are a black code on a white background, 50 pixels high. Everything else is left to the symbology.
Example
Code
Encode(Record, Text)
Encodes a value according to a Barcode Settings record - the way to control the appearance and the symbology-specific options.
Code
| Parameter | Type | Description |
|---|---|---|
barcodeSettings | Record "bdev.Barcode Settings" | The settings to use. |
value | Text | The value to encode. |
Returns the barcode image as a Temp Blob codeunit.
The settings carry the symbology, the colors, the height, the margin, whether the value is printed below the code, whether the value is in GS1 format, and the options of the chosen symbology - error correction, symbol shape, aspect ratio, encoding.
A user maintains them on the Barcode Settings page, which is usually what you want: the appearance of a barcode is a setup decision, not something to hard-code. Read the record and pass it on:
Code
Settings that are not stored anywhere work as well - initialize a record in memory, set what you need, and pass it:
Code
A symbology that cannot encode raises an error
Not every symbology supports encoding, and each accepts only a part of the settings. Encoding with a symbology that does not support it fails with an error naming the symbology; properties it does not accept are ignored silently.
Decode(Text)
Reads the barcode in a Base64 encoded image.
Code
| Parameter | Type | Description |
|---|---|---|
base64ImageData | Text | The image containing the barcode, Base64 encoded. |
Returns the decoded value.
Decode(Codeunit)
Reads the barcode in an image held in a Temp Blob codeunit - the usual case when the image comes from a Media field or an upload.
Code
| Parameter | Type | Description |
|---|---|---|
tempBlob | Codeunit "Temp Blob" | The image containing the barcode. |
Returns the decoded value.
Both overloads raise an error when the service cannot read a barcode in the image - there is no "nothing found" result to check for. Wrap the call when a missing barcode is an expected outcome:
Code
EncodeVCard(Record, Record)
Encodes a contact as a vCard barcode. Scanning it adds the contact to a phone.
Code
| Parameter | Type | Description |
|---|---|---|
barcodeSettings | Record "bdev.Barcode Settings" | The settings to use. The symbology must be vCard QR Code. |
contact / salespersonPurchaser | Record | The record the vCard is built from. |
Returns the barcode image as a Temp Blob codeunit.
What goes into the vCard differs between the two:
| vCard field | From a Contact | From a Salesperson/Purchaser |
|---|---|---|
| Name, organization | Name, Company Name | Name, company name from Company Information |
| Address | the address of the contact | the address from Company Information |
| Phone, e-mail, website | of the contact | phone and e-mail of the salesperson, website from Company Information |
| Picture | Image of the contact | Image of the salesperson |
The picture is only embedded when Include Picture is set in the settings. A vCard with a picture produces a considerably denser QR code - check that your label still scans before switching it on.
The symbology is checked
EncodeVCard raises a TestField error when the settings do not use the vCard QR Code symbology. Give the vCard its own Barcode Settings record rather than reusing the one your labels print.


