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

Notifications

Announcements

No record found.

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,245
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,545 Super User 2025 Season 2 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
    5,066 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,576 Super User 2025 Season 2 on at
    Not with the standard way out, you need to do a quick customization for this.
     
  • Suggested answer
    Aman Kakkar Profile Picture
    2,241 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
    95,307 Super User 2025 Season 2 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,147 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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,175

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,476 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,435 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans