Hello All Readers,
Let’s start with the article!!
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:
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.
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:
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.
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.
Connect with us at firstname.lastname@example.org for the D 365 Business Central consultation.
Thanking you all.