How to do it...

  1. First, let's view the existing Customer Listing report to see what it looks like:
    1. Open your web browser and go to your Business Central development sandbox.
    2. Using the  icon, search for Customer Listing and click the link to run the report.
    3. Click Preview to view the report on screen.

The report should look something like this:

  1. In Visual Studio Code, open your AL project.
  2. In Explorer, create a new file named Replace Base Reports.alIn the Editor tab, create a new codeunit object and then add the following code:
codeunit 50102 "Replace Base Reports"
{
[EventSubscriber(ObjectType::Codeunit,
Codeunit::ReportManagement, 'OnAfterSubstituteReport', '',
false, false)]
procedure OnAfterSubstituteReport(ReportId: Integer; var
NewReportId: Integer)
begin
if ReportId = Report::"Customer Listing" then
NewReportId := Report::"Customer Listing With TV
Shows";
end;
}
If you do not have the Customer Listing report in your development sandbox, you can also perform the preceding example using the Customer - List report.

Can it get any easier than this? As you can see from the code, all we need to do is replace the original report that the system was executing with our own modified version.

  1. Press F5 to build and publish your application so that we can test this out. Once it's published, go back and repeat step 1, and this time, your report should look something like this (results, of course, will vary based on your data):

As you can see, compared to the original report, we made some pretty drastic changes. We not only changed the report layout, but we also completely changed the dataset too!

Ensure that you substitute a report with one that has a compatible dataset. Some reports that are executed in the source code require specific dataset items because of the way that the logic is written. If you replace the report with an incompatible one, then you will receive errors at runtime.