Dynamics 365 Business Central: introducing the reportextension object

One of the noisy limitations on Dynamics 365 Business Central until version 17.X was the impossibility to extend standard reports. If you want to add a simple new field to a standard report, you are forced to create an entire new report (new dataset), maybe from scratch or (better) by manually copying the standard dataset into a new .al file and then modifying it. You cannot handle the report dataset as an “extendible” object open for contributions between extensions.

With Dynamics 365 Business Central 2021 Wave 1 (version 18) and AL Language version 7.x, things changes. You can now extend an existing report by making additive changes to the report dataset and request page. Report layouts will not have an extensibility model.

How to do that?

With AL 7.x, you can now define a reportextension object (with the standard treportext snippet) as follows:

reportextension Id MyExtension extends MyTargetReport
{
    dataset
    {
        // Add changes to dataitems and columns here
    }
    
    requestpage
    {
        // Add changes to the requestpage here
    }
}

In the object definition above, MyTargetReport is obviously the report that must be extended.

NOTE: when you select the report to extend from the list, you can now see a strikethrough marker on the reports that will be obsoleted:

As a simple example on how to use this new object, imagine that I want to extend the “Standard Sales – Invoice” report because I need to print a custom field “Additional Notes SD” defined in the Sales Invoice Header table:

You can now write something like the following:

Here I’m adding to the report’s dataitem called Header (in the standard AL dataset definition) the new custom field previously defined. You can also add global report’s fields to the request page and to the dataset, like for example:

You can also add a new dataitem to your report like in the following code (here I’m adding the Sales Invoice Line just as an example):

When you build the extension, the report layout is generated/updated and in the dataset you can find all the standard fields and also your newly added fields:

You can also handle the report triggers to add your business logic, for example:

Working with reports will become a little more easy now, at least the duplication of datasets (and so the maintenance of different reports) can be avoided.

Is the reportextension object perfect now? NO!

There are different things that must be fixed or simply that doesn’t work perfectly today (report triggers for example) but they should be fixed for the v18 official release. Remember also that OnInitReport will not probably be supported on report extensions in this release because it’s triggered before report extensions are loaded.

Try that on the public preview available from this week…

Comment List
Related
Recommended