How to translate attachment names
The event subscribers mentioned in this article were tested with Business Central 2023 release wave 1 (BC22). We cannot guarantee the correct working on different Business Central versions, as these event subscribers might change between versions.
When Business Central generates email attachment filenames, it uses a hardcoded way of generating them. For Business Central 2023 release wave 1 (BC22), most of these attachment names are translated. Some, however, are not. Most notable among these is the statement. The statement uses different code for email generation where the translation has not been implemented.
Fortunately, you can manually override the translations using an event subscriber.
To translate the statement, you can use the OnGenerateFileNameOnAfterAssignFileName event in the Custom Layout Reporting codeunit. The following is sample code using the ForNAV Language Setup table.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Custom Layout Reporting", 'OnGenerateFileNameOnAfterAssignFileName', '', false, false)]local procedure OnGenerateFileNameOnAfterAssignFileName(var FileName: Text; ReportID: Integer; Extension: Text; DataRecRef: RecordRef)varAllObjWithCaption: Record AllObjWithCaption;Customer: Record Customer;ForNAVLanguageSetup: Record "ForNAV Language Setup";FilenameLbl: Label '%1 - %2%3', Comment = '%1 = report caption, %2 = customer name, %3 = extension';beginif DataRecRef.Number <> Database::Customer thenexit;DataRecRef.SetTable(Customer);ForNAVLanguageSetup.SetRange("Report ID", ReportID);ForNAVLanguageSetup.SetRange("Language Code", Customer."Language Code");ForNAVLanguageSetup.SetRange("Table No.", 0);ForNAVLanguageSetup.SetRange("Field No.", 0);if not ForNAVLanguageSetup.FindFirst() then beginAllObjWithCaption.Get(AllObjWithCaption."Object Type"::Report, ReportID);FileName := StrSubstNo(FileNameLbl, AllObjWithCaption."Object Caption", Customer.Name, Extension);exit;end;FileName := StrSubstNo(FileNameLbl, ForNAVLanguageSetup."Translate To", Customer.Name, Extension);end;
To override any attachment filename, you can use the OnBeforeGetAttachmentFileName event in the Document-Mailing codeunit. Technically, you can override the statement attachment name here as well, however, there is no reliable way of getting the statement language from this event. It works well for sales and purchase documents though. The following is an example:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Document-Mailing", 'OnBeforeGetAttachmentFileName', '', false, false)]local procedure OnBeforeGetAttachmentFileName(var AttachmentFileName: Text[250]; PostedDocNo: Code[20]; EmailDocumentName: Text[250]; ReportUsage: Integer)varSalesInvoiceHeader: Record "Sales Invoice Header";ForNAVLanguageSetup: Record "ForNAV Language Setup";ReportSelectionUsage: Enum "Report Selection Usage";ReportAsPdfFileNameMsg: Label '%1 %2.pdf', Comment = '%1 = Document Type %2 = Invoice No. or Job Number';beginif PostedDocNo = '' thenexit;case ReportUsage ofReportSelectionUsage::"S.Invoice".AsInteger():beginSalesInvoiceHeader.Get(PostedDocNo);ForNAVLanguageSetup.SetRange("Report ID", 0);ForNAVLanguageSetup.SetRange("Language Code", SalesInvoiceHeader."Language Code");ForNAVLanguageSetup.SetRange("Table No.", Database::"Sales Invoice Header");ForNAVLanguageSetup.SetRange("Field No.", 0);if not ForNAVLanguageSetup.FindFirst() thenexit;AttachmentFileName := StrSubstNo(ReportAsPdfFileNameMsg, ForNAVLanguageSetup."Translate To", PostedDocNo)end;end;end;
You can see the full code in the ForNAV GitHub repository here:
https://github.com/fornav/ForNav.Training/tree/master/ForNAV.ChangeAttachmentName
Latest news
Latest knowledge base articles
-
AI Assistant in the ForNAV Designer (beta)
-
Mapping from Business Central documents to ZUGFeRD and XRechnung
-
Using native Business Central ZUGFeRD generation with FORNAV reports
-
Repeater tables and barcodes in the ForNAV Template Editor
-
Controlling report language, format region, copies, and watermark with the Report Settings page
