Hi, Readers.
Dynamics 365 Business Central 2024 wave 2 (BC25) is generally available. More details: General availability: Dynamics 365 Business Central 2024 release wave 2 (BC25).
I will continue to test and share some new features that I hope will be helpful.
In this post, I would like to talk about how to set the default filename for the downloaded reports with new OnGetFilename event in Business Central 2024 release wave 2 (BC25).
This is not yet documented in the Business Central 2024 release wave 2 (BC25) release plan and AL Language extension changelog Version 14.0, But it is mentioned in What’s new: Reporting features (for developers and consultants): 9:00~
In Business Central, you can save a report to a PDF document, Microsoft Word document, Microsoft Excel workbook, or XML document by choosing Send to, then making your selection. A file is downloaded to your computer.

Choose file type…

The file will be saved with the name (Report caption + FileExtension) by default.

As of the last version (BC24), this default file name cannot be changed. So in Dynamics 365 Business Central: How to directly export Report from page (Custom Filename For Report Export), we briefly discussed that this could be done with Report.SaveAs() + FileManagement.BLOBExport(), but this would require adding another action/process and wouldn’t be that perfect.

With this wave (BC25), this problem has been completely solved. Here is the new standard event.
codeunit 44 ReportManagement -> OnGetFilename

[IntegrationEvent(false, false)]
local procedure OnGetFilename(ReportID: Integer; Caption: Text[250]; ObjectPayload: JsonObject; FileExtension: Text[30]; ReportRecordRef: RecordRef; var Filename: Text; var Success: Boolean)
begin
end;
And here is a summary of the parameters we can get when subscribing it.

The method is also very simple, only two steps are needed
- Set Filename
- Set the Success to true (required): If not set, Filename will remain the default.

Source code: ReportID_Caption_UserId.FileExtension
codeunit 50122 ReportNameHandler
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, OnGetFilename, '', false, false)]
local procedure OnGetFilename(ReportID: Integer; Caption: Text[250]; ObjectPayload: JsonObject; FileExtension: Text[30]; ReportRecordRef: RecordRef; var Filename: Text; var Success: Boolean)
begin
Filename := Format(ReportID) + '_' + Caption + '_' + UserId + FileExtension;
Success := true;
end;
}
This applies to all reports and all download types. Let’s look at a few examples.
Standard Sales – Order Conf. (1305) -> PDF


Standard Sales – Order Conf. (1305) -> Word


Customer – Top 10 List (111) -> XML


Customer – Top 10 List (111) -> Excel (data and layout)


If you want to control which report to change the default name, it is also very simple because you can get the ReportID.
For example,

Or,

Grear. Small update, but it makes life easier. Give it a try!!!😁
END
Hope this will help.
Thanks for reading.
ZHU
コメント