Security change on December 1, 2026: TLS 1.2 will become the minimum standard for 365 business Print Agent. Details and system requirements
365 business development
365 business Barcode

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
barcode: Codeunit "bdev.Barcode";

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
procedure Encode(barcodeSymbology: Enum "bdev.Barcode Symbology"; value: Text): Codeunit "Temp Blob"
ParameterTypeDescription
barcodeSymbologyEnum "bdev.Barcode Symbology"The symbology, for example QR Code or Code 128.
valueTextThe 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
procedure AttachBarcodeToItem(var item: Record Item) var barcode: Codeunit "bdev.Barcode"; image: Codeunit "Temp Blob"; recRef: RecordRef; begin image := barcode.Encode(Enum::"bdev.Barcode Symbology"::"QR Code", item."No."); recRef.GetTable(item); image.ToRecordRef(recRef, item.FieldNo("My Barcode")); recRef.Modify(true); recRef.SetTable(item); end;

Encode(Record, Text)

Encodes a value according to a Barcode Settings record - the way to control the appearance and the symbology-specific options.

Code
procedure Encode(barcodeSettings: Record "bdev.Barcode Settings"; value: Text): Codeunit "Temp Blob"
ParameterTypeDescription
barcodeSettingsRecord "bdev.Barcode Settings"The settings to use.
valueTextThe 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
procedure EncodeWithSetup(value: Text): Codeunit "Temp Blob" var barcodeSettings: Record "bdev.Barcode Settings"; mySetup: Record "My Setup"; barcode: Codeunit "bdev.Barcode"; begin mySetup.Get(); mySetup.TestField("Barcode Settings Code"); barcodeSettings.Get(mySetup."Barcode Settings Code"); exit(barcode.Encode(barcodeSettings, value)); end;

Settings that are not stored anywhere work as well - initialize a record in memory, set what you need, and pass it:

Code
var barcodeSettings: Record "bdev.Barcode Settings" temporary; begin barcodeSettings.Init(); barcodeSettings."Barcode Symbology" := barcodeSettings."Barcode Symbology"::"Data Matrix"; barcodeSettings.Height := 80; barcodeSettings."Show Barcode Value" := true;

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
procedure Decode(base64ImageData: Text): Text
ParameterTypeDescription
base64ImageDataTextThe 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
procedure Decode(tempBlob: Codeunit "Temp Blob"): Text
ParameterTypeDescription
tempBlobCodeunit "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
[TryFunction] local procedure TryDecode(image: Codeunit "Temp Blob"; var value: Text) var barcode: Codeunit "bdev.Barcode"; begin value := barcode.Decode(image); end;

EncodeVCard(Record, Record)

Encodes a contact as a vCard barcode. Scanning it adds the contact to a phone.

Code
procedure EncodeVCard(barcodeSettings: Record "bdev.Barcode Settings"; contact: Record Contact): Codeunit "Temp Blob" procedure EncodeVCard(barcodeSettings: Record "bdev.Barcode Settings"; salespersonPurchaser: Record "Salesperson/Purchaser"): Codeunit "Temp Blob"
ParameterTypeDescription
barcodeSettingsRecord "bdev.Barcode Settings"The settings to use. The symbology must be vCard QR Code.
contact / salespersonPurchaserRecordThe 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 fieldFrom a ContactFrom a Salesperson/Purchaser
Name, organizationName, Company NameName, company name from Company Information
Addressthe address of the contactthe address from Company Information
Phone, e-mail, websiteof the contactphone and e-mail of the salesperson, website from Company Information
PictureImage of the contactImage 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.

See also

Last modified on