Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central

(4) ShareShare
ReportReport
Posted on by 183

Hello everyone,

I'm working on customizing an AL report (Cheque) in  Business Central. The report includes a field that converts numeric amounts into words (AmountInWords). However, when the converted text exceeds 45 characters, it overflows the designated textbox area on the cheque layout, disrupting the overall layout.

What I Want to Achieve:

  • Automatically insert a line break after 45 characters in the AmountInWords field.
  • Ensure that the text wraps to the next line without manual intervention.
  • Maintain the portrait orientation and alignment consistent with other fields on the cheque
Which function or syntax can help me. I've already try with something like that
local procedure InsertLineBreak(InputText: Text; MaxLength: Integer): Text
var
    FirstPart: Text[255];
    SecondPart: Text[255];
begin
    if STRLEN(InputText) <= MaxLength then
        exit(InputText);
    
    FirstPart := COPYSTR(InputText, 1, MaxLength);
    SecondPart := COPYSTR(InputText, MaxLength + 1, STRLEN(InputText) - MaxLength);
    exit(FirstPart + '\n' + SecondPart); // Tried using '\n', CRLF, and CHAR functions
end;
 
 
How can I solve it?
Thanks in advance!
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 7,593 Super User 2025 Season 1 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 7,593 Super User 2025 Season 1 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
    It looks like your system's regional settings or language settings might be affecting the output. The FORMAT function in AL respects the user's regional settings, which can sometimes cause unexpected results.
  • CU07101338-0 Profile Picture
    CU07101338-0 183 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
    Thank you it's been solved!
    but for posting date I expect to see the format like 09-OCT-2024, before using this code everything was fine but now it shows like this D-MMMM-YYYY
    I use this code
    
    local procedure FormatPostingDateCustom(ADate: Date): Text
    begin
        exit(UPPERCASE(FORMAT(ADate, 0, 'dd-MMM-yyyy')));
    end;
    
    // Dataset Column Definition
    column(PostingDate; FormatPostingDateCustom(GJLine."Posting Date"))
    {
    }
    
    Maybe this is because of the layout, because the code was ok before. How can I solve that
    Thanks in advance!
  • Verified answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 7,593 Super User 2025 Season 1 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 7,593 Super User 2025 Season 1 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
    Hi, I am not sure which check report you are using that why I have tested it on page, but yes below logic will help you out:




     
    tableextension 50140 MyExtension extends "Sales Header"
    {
        trigger OnInsert()
        var
            TypeHelper: Codeunit "Type Helper";
            Crlf: Text[2];
            InputString: Text[2048];
            FormattedString: Text[2048];
            MaxLineLength: Integer;
            CurrentLine: Text[2048];
            CharIndex: Integer;
            OutS: OutStream;
        begin
            // Constants
            Crlf := TypeHelper.CRLFSeparator();
            MaxLineLength := 45; // Maximum characters per line
     
            // Input string
            InputString := 'Business Central is a comprehensive, cloud-based enterprise resource planning (ERP) solution that helps small and medium-sized businesses streamline operations, enhance customer experiences, improve financial visibility, and facilitate data-driven decisions for better organizational growth.';
     
            FormattedString := '';
     
            // Add line breaks
            CharIndex := 1;
            while CharIndex <= StrLen(InputString) do begin
                CurrentLine := CopyStr(InputString, CharIndex, MaxLineLength);
                FormattedString := FormattedString + CurrentLine + Crlf;
                CharIndex += MaxLineLength;
            end;
     
            // Clear and write to "Work Description"
            Clear("Work Description");
            "Work Description".CreateOutStream(OutS, TextEncoding::UTF8);
            OutS.WriteText(FormattedString);
        end;
    }
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 7,593 Super User 2025 Season 1 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 76,911 Super User 2025 Season 1 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
    Hi, hope the following can give you some hints.
    Dynamics 365 Business Central: How to set multi-line text for a Blob Data Type field via AL
    Dynamics 365 Business Central: How to split a string into fixed length (Error: The length of the string is xxx, but it must be less than or equal to xxx characters)
     
    Thanks.
    ZHU
  • CU07101338-0 Profile Picture
    CU07101338-0 183 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
    Thanks for your kind reply;
    Unfortunately nothing happens with this code!
    Is there any alternative solution for that?
    How can we handle long words with too much characters. 
  • Suggested answer
    VaHiX Profile Picture
    VaHiX 4,182 Super User 2025 Season 1 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
    May this models can help you:
     
    exit(FirstPart + ENVIRONMENT.NewLine + SecondPart);
    or
    exit(FirstPart + CHAR(10) + SecondPart);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,971 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,846 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans