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