Dynamics 365 Business Central: Generate Swiss QR Code without external services/APIs

Dynamics 365 Business Central

Hi, Readers.
The barcode functionality lets you convert an alphanumeric value in a report dataset into a barcode on a generated report. The functionality is provided by the Barcode module of the System Application. The module includes the objects and tools that you need to add barcodes to reports. More details:

This is a standard function provided by Microsoft. We can simply add it in the extension using AL. However, if the customer requires a QR code in a special format, such as a special size, background color, etc., or other bar codes that are not supported by the standard, the standard cannot do it. We can do this through external services. For example,

Using external services we can also print Swiss QR Code.

More details: Dynamics 365 Business Central: Generate barcode through external services/APIs (Telepen, Swiss QR Code, QR codes with colors, images or text……)

In this post, I will share another simple way, how to generate Swiss QR Code without external services/APIs.

If you just want to generate a Swiss QR Code, Microsoft has prepared a standard method for us.

codeunit 4113 “Swiss QR Code Helper”:

Let’s look at a specific requirement. Add a new action to the Item Card to generate a Swiss QR Code containing the Item No. and Inventory, and save the generated Swiss QR Code on the Item Picture.

Great.

Very simple, you can also generate Swiss QR Code in the report, give it a try!!!😁

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

pageextension 50119 ItemCardExt extends "Item Card"
{
    actions
    {
        addafter(CopyItem)
        {
            action(GenerateQRCodeImage)
            {
                ApplicationArea = All;
                Caption = 'Generate Swiss QR Code';
                Promoted = true;
                PromotedCategory = Process;
                Image = AddContacts;

                trigger OnAction()
                var
                    SwissQRCodeHelper: Codeunit "Swiss QR Code Helper";
                    SourceText: Text;
                    QRCodeTempBlob: Codeunit "Temp Blob";
                    FileName: Text;
                    InS: InStream;
                begin
                    SourceText := Rec."No." + ': ' + Format(Rec.Inventory);
                    SwissQRCodeHelper.GenerateQRCodeImage(SourceText, QRCodeTempBlob);
                    if QRCodeTempBlob.HasValue() then begin
                        FileName := Rec."No." + '_QRCode.png';
                        QRCodeTempBlob.CreateInStream(InS);
                        Clear(Rec.Picture);
                        Rec.Picture.ImportStream(InS, FileName);
                        Rec.Modify(true);
                    end;
                end;
            }
        }
    }
}

END

Hope this will help.

Thanks for your reading.

ZHU

コメント

Copied title and URL