How to convert QR Code string in TLV Format in AL

How can I convert QR code in TLV Format in AL as my function is generating QR Code but it shows invalid in UAE VAT QR Scan Application. My QR Generating function is given below.

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";

    BarcodeString :=(CompanyInfo.Name + 'VAT Reg No:' + CompanyInfo."VAT Registration No." + 'Invoice Date' + Format(header."Document Date") + 'VAT Amount :' + Format(TotalVatAmount) + 'Invoice Amount :' + Format(total_IncVatAmt));
    QRCode := BarcodeFontProvider2D.EncodeFont(BarcodeString, BarcodeSymbology2D);
end;

TLV (Tag-Length-Value) format is a way to encode data in a standardized format. To convert your QR code into TLV format, you can follow the steps below:

  1. Break your QR code data into individual tags and values according to the TLV format. For example, you could use “01” as the tag for Company Name and “02” as the tag for VAT Registration No. The value of each tag should be preceded by its length in bytes.
  2. Encode the tags and values using the TLV format. For example, the TLV encoded string for Company Name could be “0112Company Name”, where “01” represents the tag, “12” represents the length of the value in bytes, and “Company Name” represents the actual value.
  3. Combine all the TLV encoded tags and values together to create the final TLV string.

Here is an example of how you could modify your function to generate a TLV encoded QR code:

local procedure GenerateQRCode() var BarcodeSymbology2D: Enum “Barcode Symbology 2D”; BarcodeFontProvider2D: Interface “Barcode Font Provider 2D”; BarcodeString: Text; TLVString: Text; CompanyInfoTag: Text; VATRegNoTag: Text; InvoiceDateTag: Text; VATAmountTag: Text; InvoiceAmountTag: Text;

begin BarcodeFontProvider2D := Enum::“Barcode Font Provider 2D”::IDAutomation2D; BarcodeSymbology2D := Enum::“Barcode Symbology 2D”::“QR-Code”;

// Encode each data field in TLV format
CompanyInfoTag := ‘01’ + TextEncoder.Utf8ToAnsi(CompanyInfo.Name);
VATRegNoTag := ‘02’ + TextEncoder.Utf8ToAnsi(CompanyInfo.“VAT Registration No.”);
InvoiceDateTag := ‘03’ + TextEncoder.Utf8ToAnsi(Format(header.“Document Date”, ‘YYYYMMdd’));
VATAmountTag := ‘04’ + TextEncoder.Utf8ToAnsi(Format(TotalVatAmount, 0, ‘.’, ‘’));
InvoiceAmountTag := ‘05’ + TextEncoder.Utf8ToAnsi(Format(total_IncVatAmt, 0, ‘.’, ‘’));

// Combine all the TLV tags and values into a single TLV string
TLVString := CompanyInfoTag + VATRegNoTag + InvoiceDateTag + VATAmountTag + InvoiceAmountTag;

// Generate the QR code using the TLV encoded string
QRCode := BarcodeFontProvider2D.EncodeFont(TLVString, BarcodeSymbology2D);

end;

Note that this code assumes that your VAT Registration No., TotalVatAmount, and total_IncVatAmt fields are all numeric values. If they are text values, you may need to modify the TLV encoding accordingly.