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 NewReportId
parameter.
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)]
local procedure
OnAfterSubstituteReport(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 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.
Hi, I did an extreme example and replaced a report with an complete different one. The problem is: the request page of the original report was shown and afterwards my new report was run without showing his request page. It run correctly – with dataselection and so on and with the layout, but I could not change the behaviour with the request page. Anything I missed or I did wrong?
Thanks