A long time ago I described how you can add fields to reports in BC:

How Do I: Add fields to a Report in Business Central? – think about IT

but since then a lot has changed and the Report Extension object was introduced, which is a much better solution.

 

What is a Report Extension?

With the report extension object, you can extend existing report objects, similar to how you extend tables and pages.

Currently you can:

  • Add columns to existing dataitems in the report dataset
  • Add new dataitems
  • Add trigger implementations
  • Add to request pages
  • Add to a new report layout to reflect the new fields that are added with an extension

 

Example:

As an example let’s add a field to the Standard Sales – Invoice report 1306.

The idea is to add a field: Order No., and it’s label, to the existing Standard Sales Invoice report 1306.

In VScode you need to create a new .al file and use the treportext snippet to create the skeleton .al file:

Next you give your new report extension object an ID and a NAME.

In my report extension I also want to give the user the choice, in the report request page, to include or not include the new field.

 

So we will add 3 fields to the dataset:

  • Order No. Lbl
  • Order No.
  • DisplayOrderInfo

And the request page we will also extend by adding the DisplayOrderInfo field/variable to it:

So, now your report extension looks as follows:

Note that at the bottom, in the var section, I declared the DisplayOrderInfo boolean.

 

The report extension layout:

The next part is to create a layout for the report extension. You can do that by adding the RDLCLayout and/or WORDLayout properties. In this example I have chosen to add an RDLC layout.

Once you have added the layout property, you can generate the layout file by packaging the project:

This command will generate the rdlc file and then you can open it externally:

I have Visual Studio installed, so the layout opens in Visual Studio. As an alternative you can also work with Report Builder.

 

This is what the layout looks like now:

 

What is the problem?

Well, the good thing is that we have a layout and the dataset, and our new fields are in the dataset, however the layout is completely empty. So if we want to continue with it, we would have to completely recreate it, as it was in the original report, and then add our new field(s).

 

There’s an easier way to do this.

We will not use this layout, because it is empty. Instead we are going to reuse the existing layout for the base report. To do that, we need to open Business Central and go to the Report Layout Selection page:

In the Report Layout Selection page, filter it on report 1306, as shown above.

Now we will add a new custom layout to the report, which will be a copy of the built inn layout:

Once we now have a copy of the built inn layout, we can export it:

 

The .rdlc file now downloads and you need to copy the rdlc file to your VScode project folder, and then rename it to StandardSalesInvoiceExtended.rdlc:

 

And now you need to repackage the project, so the new fields you added in the dataset of the report extension are added in the copied rdlc layout:

 

When you now open the rdlc file in Visual Studio, you will have the updated dataset and also the original layout:

 

Update the new layout:

The next part is to make your changes, add your new field(s), to the layout.

For example:

 

Apply the new layout in BC:

Our work in VSCode is done now. Next we need to publish the app to BC.

After you app containing the report extension and new layout is deployed to BC, you need to set the new layout as the default one, in the Report Layout Selection page.

 

Layouts that are included in a report extension will show up in Business Central as built-in layouts. The layout in a report extension will not automatically be used when the report extension is deployed. To use the report extension layout, go to the Report Layout Selection page in Business Central, make sure to choose to use a built-in layout in the Selected layout field, and then choose the layout for the report in question from the Custom Layout Description drop-down box.

 

Once you have done this, you can test it by printing a sales invoice:

And voila, your new layout is here, with the new field(s)! 🙂

 

More information is available here:

Report Extension Object – Business Central | Microsoft Docs

Report Extension Example – Business Central | Microsoft Docs

7 Thoughts on “How do I: Create a Report Extension to add a field to the dataset of a Report?

  1. Hello
    How I can add lookup field on the report to print multi selected values on this field.

Leave a Reply

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

Post Navigation