In Microsoft Dynamics 365 Business Central, report extensions allow you to extend existing reports without modifying the original report objects. This feature is useful for adding new data fields, custom layouts, and additional functionality to standard reports. Let’s deep dive in the topic,
What is a Report Extension?
With the report extension object, you can extend existing report objects, like how you extend tables and pages. With report extensions, you can extend an existing report by:
- Adding columns to existing dataitems in the report dataset
- Adding new dataitems
- Adding trigger implementations
- Adding to request pages
- Adding 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.
Now we will add to fields to the dataset of this report – Order no. and Its label (which is string “Order No.”) to display order no. to the existing standard Sales Invoice report.
This report can be accessed through posted sales invoice page à print/send à print it will generate our ‘sales – invoice’ report.
Now let’s write our AL program for report extension in VS code.
- Create a new project and add a new .al file to extend a report
- Here we can use treportext snippet. it will create the basic code for the report extension in our empty file as shown below.
- In that we can modify It’s ID and NAME as per our requirement and in the target report we have to give the name “Standard Sales – Invoice” which is the name of our report number 1306.
In my report extension I also want to give the choice to a user weather he/she wants to include these two new fields to the report or not. That’s why we must use another 3rd field is for conditional filter.
So, we have to add 3 fields to the dataset:
- Order No. Lbl
- Order No.
- DisplayOrderInfo
To implement that purpose, we will also add one extra field (DisplayOrderInfo) to the request page to filter the report.
So, now our report extension file looks as shown below:
Note that at the end of the file, in the var section, I declared the DisplayOrderInfo Boolean to make it a switch like enable or disable.
The report extension layout:
The next step is to make changes in the layout of our standard report. We can do it in both the ways either RDLC or word layout. But here we will use RDLC layout. That’s why we will add RDLC layout properties in our report extension.
After adding this property, we can create a package of our project by pressing ctrl+shift+B which will create an RDLC file for our report layout.
As we have just created this rdlc layout it does not contain any design, but it contains the dataset of original report as well as newly added dataitems. I have Open it with MS Report Builder.
This is what the layout looks like now:
Do we have to design the report from scratch?
No, absolutely not. Here we have all the required dataset but don’t have the layout for the report. Here you don’t have to design the whole layout in this empty file. I will show you the easier way to get the original layout from standard report.
There’s an easier way to get the layout.
We will use standard original report layout and then modify it as per our requirement.
- Go to the page ‘Report Layout Selection’ page in business central. In that page search for the report ‘1306’
- Then click on ‘Custom Layout’ tab.
- Create a new custom report layout by clicking on ‘New’ and enable the ‘Insert RDLC Layout’ and then press the button ‘OK’.
It will create an RDLC copy of the word report layout available on standard BC
Now we can export this RDLC layout copy in our system by Layout > Export Layout
The .rdlc file will be downloaded in your system and we can rename it as per our rdlc layout name (StandardSalesInvoiceExtended.rdlc) and set its path as per we have mentioned earlier in our report extension file.
Now we will create a package again with ctrl+shift+B and will see our 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: here I want to display my two fields separated with ‘:’ for that I will add an expression as shown below. And I want to show these changes only if DisplayOrderInfo is selected, that’s why I will add the expression in the row visibility tab to show or hide this row based on the expression.
Apply the new layout in BC:
Now in business central, open the Report Layout Selection, choose the report number 1306 than go to the custom layout and import this modified rdlc layout file in the previously copied rdlc layout. After that update this new layout to make it default layout in the Report Layout Selection page.
Once you have done this, you can test it by printing a sales invoice:
And yeah! It works… it will show our new fields in the report.
Thank you for investing your time to read our blog! We’re passionate about sharing valuable insights to help you navigate the world of Business Central.
If you’re curious about how we can assist you in reaching your goals, don’t hesitate to get in touch. Our dedicated team is ready to provide support every step of the way.
Let’s turn your vision into reality together!