How to generate QR code for Dynamics 365 Business Central Page URL (For example, embed the customer card URL in QR code)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about an interesting topic, how to generate QR code for Dynamics 365 Business Central Page URL (For example, embed the customer card URL in QR code).

Recently I received this question, the customer wants to print this QR code on the report, is it possible? Yes. In short, this requires two steps, first you need to generate the URL of the current page, such as the opened Customer Card. Then embed this URL into the QR code and print it out.

We have discussed how to generate URL in how to open a page in a new browser tab via AL (Run an object in a new tab).

Key method:
System.GetUrl() Method: Generates a URL for the specified client target that is based on the configuration of the server instance. If the code runs in a multitenant deployment architecture, the generated URL will automatically apply to the tenant ID of the current user.
For example,

Test video:

And starting with Business Central 2021 wave 2 (BC19.1), Microsoft brought us 2D barcodes functionality. More details: Using 2D barcodes Font in BC Online/SaaS (Aztec, Data Matrix, Maxi Code, PDF417, QR-Code)

Let me do a small update.

Add a new action to the customer card to run the report.

Pass in some records when opening the report, including the Barcode URL.

Layout:

Scanning test:

Test video: looks good😁.

Give it a try!!!😁

PS: Please note that you can generate URL for some pages without opening the page, but not for the Card, CardPart, and Document pages. More details: Filtering Data by the Web Client URL

ParameterDescription
bookmarkSpecifies a record in the underlying table of the page. The value of a bookmark is an alphanumeric string of characters, for example, 27%3bEgAAAAJ7CDAAMQA5ADAANQA4ADkAMw%3d%3.

For the page types Card, CardPart, and Document, the bookmark specifies the record that is shown in the page. For page types List, ListPart, and Worksheet, the bookmark specifies the record that is selected in the list on the page.

Important: Bookmarks are generated automatically. You can only determine a value for the bookmark by displaying the page in the Web client and looking at its address. So, a bookmark is only relevant when the address you’re working with was copied from another page instance.

Source Code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
Layout file:

pageextension 50101 CustomerListExt extends "Customer Card"
{
    actions
    {
        addafter("Sent Emails")
        {
            action(OpenCustomerCard)
            {
                Caption = 'Open Customer Card';
                ApplicationArea = All;
                PromotedCategory = Process;
                Promoted = true;
                Image = Open;
                trigger OnAction()
                begin
                    Hyperlink(GetUrl(ClientType::Current, CompanyName, ObjectType::Page, Page::"Customer Card", Rec));
                end;
            }

            action(CustomerCardBarCode)
            {
                Caption = 'Customer Card Barcodes';
                ApplicationArea = All;
                PromotedCategory = Process;
                Promoted = true;
                Image = Report;

                trigger OnAction()
                var
                    RepCustomerCardBarCode: Report CustomerCardBarCode;
                begin
                    RepCustomerCardBarCode.AssignBarcodeURL(Rec."No.", Rec.Name, GetUrl(ClientType::Current, CompanyName, ObjectType::Page, Page::"Customer Card", Rec));
                    RepCustomerCardBarCode.Run();
                end;
            }
        }
    }
}

report 50100 CustomerCardBarCode
{
    UsageCategory = Administration;
    ApplicationArea = All;
    DefaultLayout = RDLC;
    Caption = 'Customer Card Barcodes';
    RDLCLayout = 'CustCardBarcodes.rdl';
    dataset
    {
        dataitem(Customer; Customer)
        {
            DataItemTableView = sorting("No.");
            RequestFilterFields = "No.";

            column(CustomerNo; CustomerNo)
            {
            }
            column(CustomerName; CustomerName)
            {
            }
            column(BarcodeURL; BarcodeURL)
            {
            }
            column(QRCode; QRCode)
            {
            }
            trigger OnAfterGetRecord()
            begin
                GenerateQRCode();
            end;
        }
    }

    requestpage
    {
        layout
        {
            area(content)
            {
                group(URL)
                {
                    field(BarcodeURL; BarcodeURL)
                    {
                        Caption = 'Barcode URL';
                        ApplicationArea = All;
                        MultiLine = true;
                        Editable = false;
                    }
                    field(CustomerNo; CustomerNo)
                    {
                        Caption = 'Customer No.';
                        ApplicationArea = All;
                        Editable = false;
                    }
                    field(CustomerName; CustomerName)
                    {
                        Caption = 'Customer Name';
                        ApplicationArea = All;
                        Editable = false;
                    }
                }
            }
        }

        trigger OnOpenPage()
        begin
            CustomerNo := Customer."No.";
            CustomerName := Customer.Name;
        end;
    }

    var
        QRCode: Text;
        BarcodeURL: Text;
        CustomerNo: Code[20];
        CustomerName: Text[100];

    local procedure GenerateQRCode()
    var
        BarcodeSymbology2D: Enum "Barcode Symbology 2D";
        BarcodeFontProvider2D: Interface "Barcode Font Provider 2D";
        BarcodeString: Text;
    begin
        BarcodeFontProvider2D := Enum::"Barcode Font Provider 2D"::IDAutomation2D;
        BarcodeSymbology2D := Enum::"Barcode Symbology 2D"::"QR-Code";
        QRCode := BarcodeFontProvider2D.EncodeFont(BarcodeURL, BarcodeSymbology2D);
    end;

    procedure AssignBarcodeURL(CustNo: Code[20]; CustName: text[100]; NewBarcodeURL: Text)
    begin
        Customer."No." := CustNo;
        Customer.Name := CustName;
        BarcodeURL := NewBarcodeURL;
    end;
}

END

Hope this will help.

Thanks for your reading.

ZHU

コメント

Copied title and URL