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...
Suggested answer

Change Email Attachment File Name

(1) ShareShare
ReportReport
Posted on by 3,944
How can I change the default naming format of the Email Attachment file name. For example the default file name below is 'Sales Quote S-QUO1001.pdf'. I would like to change the default Name to include Customer Name for example 'Trey Research S-QUO1001.pdf'.
 
I have the same question (0)
  • Suggested answer
    Yi Yong Profile Picture
    2,464 Super User 2025 Season 2 on at
    Change Email Attachment File Name
    Hello DinB,
     
    You can do it via customize and subscribe to the below event.
     
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Document-Mailing", 'OnBeforeGetAttachmentFileName', '', false, false)]

    local procedure OnBeforeGetAttachmentFileName(var AttachmentFileName: Text[250]; PostedDocNo: Code[20]; EmailDocumentName: Text[250]; ReportUsage: Integer);
    begin
    // Use 'ReportUsage' for different sending events.
    // For example ReportUsage = 2 is for Posted Sales Invoice.
    end;
  • Suggested answer
    Shrey Chauhan Profile Picture
    284 on at
    Change Email Attachment File Name
    Hello,

    Here's the Code to change the Attachment File Name :
     
    codeunit 50008 "Attachment FileName"
    {
        [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
            SalesInvoiceHeader: Record "Sales Invoice Header";
            ForNAVLanguageSetup: Record "Email Attachments";
            ReportSelectionUsage: Enum "Report Selection Usage";
            ReportAsPdfFileNameMsg: Label '%1 %2.pdf', Comment = '%1 = Document Type %2 = Invoice No. or Job Number';
        begin
            if PostedDocNo = '' then
                exit;
            case ReportUsage of
                ReportSelectionUsage::"S.Invoice".AsInteger():
                    begin
                        SalesInvoiceHeader.Get(PostedDocNo);
                AttachmentFileName := "Custom Name"
                    end;
            end;
        end;
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Custom Layout Reporting", 'OnGenerateFileNameOnAfterAssignFileName', '', false, false)]
        local procedure OnGenerateFileNameOnAfterAssignFileName(var FileName: Text; ReportID: Integer; Extension: Text; DataRecRef: RecordRef)
        var
            AllObjWithCaption: Record AllObjWithCaption;
            Customer: Record Customer;
            ForNAVLanguageSetup: Record "ForNAV Language Setup";
            FilenameLbl: Label '%1 - %2%3', Comment = '%1 = report caption, %2 = customer name, %3 = extension';
        begin
            if DataRecRef.Number <> Database::Customer then
                exit;
            DataRecRef.SetTable(Customer);
           
            FileName := "Custom Name";
        end;
    }

    Hope this Solution's Help.

    Thank You,
    Shrey Chauhan

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 3,750

#2
Sumit Singh Profile Picture

Sumit Singh 2,689

#3
YUN ZHU Profile Picture

YUN ZHU 1,987 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans