MonthMarch 2019

Replacing Base Application Reports

Maybe I didn’t look hard enough, but I went looking at the Microsoft Docs online help for Business Central for a project I’m working on, and I could not find any information on this. I did find it listed in the AL Language Extension changelog, so figured I’d throw up a quick post to get this out there in case you don’t read the changelog. 🙂

With the Business Central Fall 2018 release, it’s now possible to override base reports with your AL extension. Not just printed reports, but processing reports too!

You can do that by creating a subscriber to the OnAfterSubstituteReport event in the ReportManagement codeunit (I thought we wanted to get rid of management codeunits 😉 !?) It’s a very straightforward bit of code and it looks like this:

codeunit 50100 "Replace Reports"
    [EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnAfterSubstituteReport', '', false, false)]
    local procedure OnAfterSubstituteReport(ReportId: Integer; var NewReportId: Integer)
        if ReportId = Report::"Customer Listing" then
            NewReportId := Report::"My New Customer Listing";

As you can see, very simple logic that just replaces the report that is being executed by the system.

The above logic can be enhanced to check to see if the report has already been substituted by another extension. You can do that just by comparing the ReportId and NewReportId parameters before making your change. If those parameters do not match, and NewReportId is not -1, then the report has already been replaced by another extension, and you’re of course then going to have to figure out how you handle that.

Remember when you are replacing base reports, if the report is called in code, make sure you use a compatible report, or you’ll get run time errors.

Oh, one more piece of good news here………the event above that we subscribed to is called every time a user clicks on a report action on a page, and also when any of the following commands are executed in code for a report object:

  • Run
  • RunModal
  • SaveAsHtml
  • SaveAsXml
  • SaveAsPdf
  • SaveAsExcel
  • SaveAsWord
  • RunRequestPage
  • Execute
  • Print
  • SaveAs

That’s all for today. Happy coding!!

Multi-level App Dependencies [UPDATE]

A little bit ago I posted this article on indirect app dependencies. Based on what I was seeing, it appeared as though if your app has a dependency, and the dependent app has its own dependencies, you have to put all of the dependencies in your app, making things very difficult to manage.

Shortly after my post, fellow MVP Erik Ernst published an article stating that this is not the way it works, and he published a sample project on GitHub to try it out. Things got a bit weird here, as I grabbed his sample project and tried it for myself using his instructions. I got the same results as I first saw, and not what Erik said he saw.

After some back and forth and some research into this, it turns out that this was a change in behavior with the particular AL Language extension that I was using. I was using the VSIX from the Business Central insider registry. When I retested Erik’s instructions using the latest official Business Central release (Fall 2018 Update 3) everything worked as he stated.

This is great news. I wasn’t going crazy!

However, it was still a question if this was a bug or a new ‘feature’.

After logging to Microsoft, it was confirmed to be a bug in the insider version of the VSIX.


This means that you do NOT need to define any indirect dependencies in your app if you are not referencing any entities or functions from the app.

Glad this got sorted out. Happy coding!!

© 2020 NAV Bits and Bytes

Theme by Anders NorénUp ↑