Hi, Readers.
Today I would like to share another mini tip about Business Central, how to add a “TAB” character to a string via AL. This is a problem I recently encountered in a project. A client wanted to use the “TAB” character in the barcode to split the data. For example, Item No. + “TAB” character + Base Unit of Measure + “TAB” character + Inventory.
Because the “TAB” key on the keyboard cannot actually be used to type “TAB”, I initially thought it was impossible. Then I thought of the standard CodeUnit, CodeUnit 10 “Type Helper” which has the following method to handle special characters.

PS: For examples of how to use square brackets, please refer to the following examples.
1. Dynamics 365 Business Central: How to extract characters from a string (indexing with [])
2. Dynamics 365 Business Central: How to capitalize the first letter of each word in a string (For example: NEW YORK -> New York)
So I wonder if we can do it this time using a similar method. First, you need to find the number for the “TAB” character, 9.
Character set (0 – 127):


Then we can add it to the code. For example,

Done.


It’s very simple. And if you need to read a string consisting of the “TAB” character in the BC terminal, you can also split it using the following method, which I have tested and it works without any problems.

Great, give it a try!!!😁
Test code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
Test Layout:
report 50112 "Item Info"
{
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
DefaultRenderingLayout = RDLC;
dataset
{
dataitem(Item; Item)
{
column(No_; "No.")
{
}
column(Base_Unit_of_Measure; "Base Unit of Measure")
{
}
column(Inventory; Inventory)
{
}
column(QRCode; QRCode)
{
}
trigger OnAfterGetRecord()
begin
GenerateQRCode();
end;
}
}
rendering
{
layout(RDLC)
{
Type = RDLC;
LayoutFile = 'ItemInfo.rdl';
}
}
var
QRCode: Text;
local procedure GenerateQRCode()
var
BarcodeSymbology2D: Enum "Barcode Symbology 2D";
BarcodeFontProvider2D: Interface "Barcode Font Provider 2D";
BarcodeString: Text;
TabChar: Char;
begin
TabChar := 9;
BarcodeFontProvider2D := Enum::"Barcode Font Provider 2D"::IDAutomation2D;
BarcodeSymbology2D := Enum::"Barcode Symbology 2D"::"QR-Code";
BarcodeString := Item."No." + TabChar + Item."Base Unit of Measure" + TabChar + Format(Item.Inventory);
QRCode := BarcodeFontProvider2D.EncodeFont(BarcodeString, BarcodeSymbology2D);
end;
}END
Hope this will help.
Thanks for reading.
ZHU




コメント