It is possible to substitute reports from the base application with “custom reports“. Great!
This can be done by subscribing to the “OnAfterSubstituteReport” event published by “Codeunit 44 – ReportManagement“.
The following code illustrates “how to subscribe” a method to the “OnAfterSubstituteReport” event. This method replaces the report specified by the
ReportId with the one given by the
In this example the
"Customer - List" report will be substituted for
"My New Customer - List"
codeunit 50100 “Substitute Report”
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, ‘OnAfterSubstituteReport’, ”, false, false)]
OnAfterSubstituteReport(ReportId: Integer; var NewReportId: Integer)
if ReportId = Report::”Customer – List” then
NewReportId := Report::”My New Customer – List”;
When the “OnAfterSubstituteReport” event is raised, the event subscriber method is called and the replacement takes place.
The event is called OnAfterSubstituteReport to match the pattern followed by other events in the ReportManagement codeunit, but the subscriber will be invoked before the substitution takes place.