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…

7 Comments

  1. I have been trying to customize a report
    for the report Purchase – Receipt I want to add the full name of the modified user
    I believe it is using table Purch. Rcpt. Header

    i would apricate if you can guide me.
    either by extending report or old by way duplicating the existing report

    thank you

    Like

    1. You can create a reportextension object and in the OnAfterGetRecord trigger of the Purch. Rcpt. Header table you can read the user details, fill some global variables and then print them in the report body.

      Like

      1. could you please do with the code.
        here is what i am trying.
        since i an new i an buying your book.
        thanks for the help

        reportextension 50101 PurchaseReceiptExt1 extends “Purchase – Receipt”
        {
        dataset
        {
        addfirst(“Purch. Rcpt. Header”)
        {
        dataitem(User; User)
        {
        DataItemLink = “User Security ID” = field(SystemModifiedBy);
        DataItemLinkReference = “Purch. Rcpt. Header”;
        column(Full_Name; “Full Name”) { }

        }
        }

        }

        }

        Like

  2. It seems that it is now giving error “This feature is under development and cannot be used in an extension” when you try to use modify(), which means it is not possible to run trigger onAfterGetRecord on an existing data item. You can however add a nested data item with a direct link to the original data item and set a trigger there.

    Do you find the same issue?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.