Skip to content

Extending Reports with the Document Central Barcode

In this documentation we will create an extension that extends a report in Business Central with Document Central. Extending a report with Document Central code is used so that when a report is printed or a document is posted/converted, it is possible to automatically generate and add a Document Central Barcode during that process.

There are two ways to do this:

In the case of a custom report, you can insert the code directly into the report. In the case of other reports, you can create a report extension that executes the code. There is also a difference between Word reports and RDLC reports.

The following requirements must be met:

  • The Document Central module must be licensed.
  • CORE must be available in the extension as a reference.
  • Document Central must be present in the extension as a reference.

Learn more about Creating a Word layout report in Microsoft Business Central.

Learn more about Creating a RDLC layout report in Microsoft Business Central.

Extension of RDLC Reports with a Document Central Barcode:

  1. We will now apply a Document Central Barcode to a report you have selected.
  2. Please create a ne .al file in VS Code.
  3. Now insert the following code into the newly created file:
AL
reportextension 5227509 "DMSDI_EXT Test" extends XXX
{
    dataset
    {
        add(Header)
        {
            column(Global_Barcode; GlobalBarcode)
            { }
        }
        modify(Header)
        {
            trigger OnAfterAfterGetRecord()
            var
                LocalBarcodeText: Text;
                LocalEnumSIMDITypeOfBarcodes: Enum "SIM_DI Type of Barcodes";
                LocalSIMDIBarcodeMgt: Codeunit "SIM_DI Barcode Management";
                LocalCodeunitSIMDMSSI: Codeunit "SIM_DMS SI";
                LocalRRef: RecordRef;
            begin
                if LocalCodeunitSIMDMSSI.GetPdfPrint() then
                    exit;

                LocalRRef.Get(Header.RecordId());
                LocalBarcodeText := LocalSIMDIBarcodeMgt.CreateBarcode(LocalRRef, Header."No.", '', XXX, false);
                GlobalBarcode := LocalSIMDIBarcodeMgt.CreateLabel(LocalBarcodeText, 250, 600, true, Format(LocalEnumSIMDITypeOfBarcodes::Code128), 'PNG');
            end;
        }
    }
    var
        GlobalBarcode: Text;
}

Info

In the enum "LocalEnumSIMDITypeOfBarcodes" all supported types of barcodes are stored. To change the barcode type, select the corresponding value of the enum.

  1. Change the "XXX" to the report you want to edit.
  2. Publish this extension.
  3. Open the personalised report design in Business Central.
  4. Click on the action "New".
  5. Enter the report ID of the report you want to extend with the barcode.
  6. Select RDLC Layout.
  7. Open the .rdl file.
  8. Under the "Insert" tab, you must now add an image to the layout: image
  9. Find a place where you want to place the barcode.
  10. Right-click on the image you have addes & press "Image properties".
  11. The following changes have to be made:
    1. General:
      1. Name -> Barcode
      2. Image origin -> Database
      3. Use this field -> =System.Convert.FromBase64String(Fields!Global_Barcode.Value)
      4. Use this MIME type -> image/bmp
    2. Size:
      1. Display -> Fit Proportional
    3. Visibility:
      1. Expression -> =IsNothing(Fields!Global_Barcode.Value) OR (Globals!PageNumber>1)
  12. Save the .rdl file.
  13. Open the Personalised Report Design again in Business Central and click on the entry you have created
  14. Click on the "Import Layout" action under the Layout tab and select the .rdl file you edited.
  15. Go to the report layout selection.
  16. Select the report you have edited and change the layout to the one you have just created.
  17. When you print this report, a barcode should be printed.

Extension of Word Reports with a Document Central Barcode:

  1. Apply a Document Central Barcode to a report you have selected.
  2. Create a new .al file in VS Code.
  3. Insert the following code into the newly created file, or use your own blob field instead of the "SIM_CORE Temp Table" record blob field. This field must have only the subtype "Bitmap" or no subtype at all.:
AL
reportextension 5227509 "DMSDI_EXT Test" extends XXX
{
    dataset
    {
        add(Header)
        {
            column(Global_Barcode; GlobalRecordSIMCORETempTable."Blob 1")
            { }
        }
        modify(Header)
        {
            trigger OnAfterAfterGetRecord()
            var
                LocalSIMDIBarcodeMgt: Codeunit "SIM_DI Barcode Management";
                LocalCodeunitBase64Convert: Codeunit "Base64 Convert";
                LocalCodeunitSIMDMSSI: Codeunit "SIM_DMS SI";
                LocalEnumSIMDITypeOfBarcodes: Enum "SIM_DI Type of Barcodes";
                LocalRecordRef: RecordRef;
                LocalOutStream: OutStream;
                LocalBarcodeText: Text;
                LocalBarcodeBase64Text: Text;
            begin
                if LocalCodeunitSIMDMSSI.GetPdfPrint() then
                    exit;

                LocalRecordRef.Get(Header.RecordId());
                LocalBarcodeText := LocalSIMDIBarcodeMgt.CreateBarcode(LocalRecordRef, Header."No.", '', XXX, false);
                LocalBarcodeBase64Text := LocalSIMDIBarcodeMgt.CreateLabel(LocalBarcodeText, 250, 600, true, Format(LocalEnumSIMDITypeOfBarcodes::Code128), 'PNG');
                GlobalRecordSIMCORETempTable."Blob 1".CreateOutStream(LocalOutStream);
                LocalCodeunitBase64Convert.FromBase64(LocalBarcodeBase64Text, LocalOutStream);
            end;
        }
    }
    var
        GlobalRecordSIMCORETempTable: Record "SIM_CORE Temp Table";
}

Info

In the enum "LocalEnumSIMDMSDITypeOfBarcodes" all supported types of barcodes are stored. To change the barcode type, select the corresponding value of the enum.

  1. Change the "XXX" to the report you want to edit.
  2. Publish this extension.
  3. Open the word file of the report.
  4. Under the "Developer" tab, you need to select "XML Mapping Pane": image
  5. Select the added line and add it as an image: image
  6. Save the Word file.
  7. When you print this report, a barcode should be printed.