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
Discover more from think about IT
Subscribe to get the latest posts sent to your email.
Hello
How I can add lookup field on the report to print multi selected values on this field.
Please explain in more detail what yo mean?
I can also recommend this webinar: https://plataan.tv/en/plataan/training-course/business-central/webinar-reporting-with-microsoft-dynamics-365-business-central
Okay, I have added a new field on the sales quote page.
field(“Payment Terms License”; Rec.”Payment Terms License”)
{
Caption = ‘Payment Terms’;
ApplicationArea = All;
trigger OnLookup(var Text: Text): Boolean
var
PaymentTermsList: Page "Payment Terms License";
begin
Clear("Payment Terms License");
PaymentTermsList.LookupMode(true);
if PaymentTermsList.RunModal() = Action::LookupOK then begin
Text += PaymentTermsList.GetSelectionFilter();
exit(true);
end else
exit(false);
end;
}
On this field I can select multi lines from the lookup.
But When I print this field on the sales quote report its still empty, but when I select one line its print on the report.
Why not put a normal field on your request page, with a simple table relation, and then use GetFilters to retrieve the selected values?
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-getfilters-method
https://thinkaboutit.be/2019/12/how-do-i-add-filters-in-a-report-in-vscode-with-al/
Thanks for your help.
If you can explain to me in detail how to use GetFilters to retrieve the values specified in my example which I have attached earlier for you, I will be happy for you as I am still a beginner in using AL language and need help in solving my problem.
I’m sorry, but if the syntax of GetFilters, https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-getfilters-method, is not clear to you, because you are a beginner in AL, then I suggest to have a look at possible trainings:
https://businesscentralbooster.com/the-business-central-developer-learning-journey/
This course is full of practical examples and will get you started to develop in AL, including reports 🙂
By the way, you can add the Payment Terms, as a standard field, in the Request Page of that report. No coding required: