Substitute a report
To substitute a report, you can create a method and subscribe it to the OnAfterSubstituteReport event, as shown in the following code. The OnSubstituteReport method replaces the report that is specified by the ReportId with the one given by the NewReportId parameter.
In the following example, the Customer - List report will be substituted for the My New Customer - List report.
codeunit 50100 "Substitute Report"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnAfterSubstituteReport', '', false, false)]
local procedure OnSubstituteReport(ReportId: Integer; var NewReportId: Integer)
begin
if ReportId = Report::"Customer - List" then
NewReportId := Report::"My New Customer - List";
end;
}
When the OnAfterSubstituteReport event is raised, the event subscriber method is called and the substitution takes place.
The event is called OnAfterSubstituteReport to match the pattern that is followed by other events in the ReportManagement codeunit, but the subscriber will be invoked before the substitution takes place.
The OnAfterSubstituteReport event is raised when:
The user activates a page action that runs the report to be substituted, that is, an action that has the RunObject property set to the report.
The report is invoked from the Tell Me window.
The report is called by one of the following static methods:
Run method
RunModal method
SaveAsHtml method
SaveAsXml method
SaveAsPdf method
SaveAsExcel method
SaveAsWord method
RunRequestPage method
Execute method
Print method
SaveAs method
The codeunit 44 ReportManagement, contains events you can also subscribe to:
OnAfterGetPrinterName
OnAfterDocumentPrintReady
OnAfterGetPaperTrayForReport
OnAfterGetPrinterName
OnAfterHasCustomLayout
OnAfterDocumentReady
OnAfterDocumentDownload
OnAfterSetupPrinters
OnCustomDocumentMergerex
OnAfterSubstituteReport
We recently added new business events so that AL developers can react when a file has been generated from a report request page or if a file is ready for download.
Three new business events are added to codeunit 44 ReportManagement:
OnAfterDocumentReady
OnAfterDocumentDownload
OnCustomDocumentMerger
The OnAfterDocumentReady event is raised by the Business Central platform when a document is ready after it has been scheduled from a report request page.
The OnAfterDocumentDownload event is raised by the Business Central platform after a user has generated a report artifact from code or from a request page action.
The OnCustomDocumentMerger event is raised by the Business Central platform when the user has specified a custom report layout type which will be rendered into an artifact in application code.