web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
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 254

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!
I have the same question (0)
  • Suggested answer
    Vahid Ghafarpour Profile Picture
    11,974 Super User 2025 Season 2 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);
  • CU07101338-0 Profile Picture
    254 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
    YUN ZHU Profile Picture
    92,590 Super User 2025 Season 2 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
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,137 Super User 2025 Season 2 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,137 Super User 2025 Season 2 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;
    }
  • Verified answer
    Khushbu Rajvi. Profile Picture
    19,137 Super User 2025 Season 2 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central
  • CU07101338-0 Profile Picture
    254 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!
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,137 Super User 2025 Season 2 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.
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,137 Super User 2025 Season 2 on at
    How to Automatically Insert Line Breaks After 45 Characters in AL Report for Business Central

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,160

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,943

#3
Sumit Singh Profile Picture

Sumit Singh 2,823

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans