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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

AL code - change file name of PDF download

(7) ShareShare
ReportReport
Posted on by 3,297
Hi All
Currently when downloading reports such as invoice shows a standard name such as invoice (or document), is there a way to set the downloaded file name to something such as Invoice No 1234 etc
I have the same question (0)
  • Suggested answer
    CU02110650-0 Profile Picture
    4 on at
    a
     
  • Verified answer
    Yi Yong Profile Picture
    2,612 Super User 2026 Season 1 on at
    hello,
     
    you will need to customize this.
    there is a codeunit: Document-Mailing, OnBeforeGetAttachmentFileName function event you can subscribe to.
     
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Document-Mailing", 'OnBeforeGetAttachmentFileName', '', false, false)]
        local procedure OnBeforeGetAttachmentFileName(var AttachmentFileName: Text[250]; PostedDocNo: Code[20]; EmailDocumentName: Text[250]; ReportUsage: Integer);
        var
            lrec_SIH: Record "Sales Invoice Header";
        begin
            if ReportUsage = 2 then
                if lrec_SIH.Get(PostedDocNo) then
                    AttachmentFileName := Format(lrec_SIH."Sell-to Customer No.") + '_' + Format(PostedDocNo) + '.pdf';
        end;
     

    ReportUsage is from enum 77 "Report Selection Usage".
  • Suggested answer
    OussamaSabbouh Profile Picture
    10,972 Super User 2026 Season 1 on at
    Hello,

    Yes, you can change the downloaded file name of a report, but only by customizing it in AL.
    Business Central does not allow this through standard setup.
    How to do it (simple AL change)
    In your report extension, override OnInitReport() or OnPreReport() and use:
     
    Report.SetOutputFileName('Invoice No ' + Rec."No.");

    For example:
    reportextension 50100 MyInvoiceExt extends "Sales Invoice"
    {
        trigger OnInitReport()
        begin
            Report.SetOutputFileName('Invoice_' + "Sales Invoice Header"."No.");
        end;
    }

    Now the downloaded file will appear as:
    Invoice_1234.pdf
     
    Regards,
    Oussama Sabbouh
  • Suggested answer
    RockwithNav Profile Picture
    8,846 Super User 2026 Season 1 on at
    Not with the standard way out, you need to do a quick customization for this.
     
  • Suggested answer
    Aman Kakkar Profile Picture
    2,977 Super User 2026 Season 1 on at
    Hi,
     
    Agreed with other experts, you will need some custom code to achieve this.
     
    It’s best to make the logic setup-based, so if your naming convention changes in the future, you can simply update it from the front end without modifying the code again.
     
    Hope this helps,
    Aman K
  • Verified answer
    YUN ZHU Profile Picture
    97,970 Super User 2026 Season 1 on at
    Hi, hope the following helps.
    Business Central 2024 wave 2 (BC25): Set the default filename for the downloaded reports (Custom Filename For Report Export) – OnGetFilename event
     
    Thanks.
    ZHU
  • Suggested answer
    Rishabh Kanaskar Profile Picture
    6,213 Super User 2026 Season 1 on at
    Hi,
     
    There’s no standard setting for this, it requires AL customization.
     
    Thanks
    Rishabh

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,161 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,046 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 932 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans