In my blog post: How Do I : Create a Report, and layout, in VSCode? I explained the basics on how you can create a simple report for Business Central. In this post, and due to many requests, I will explain how you can get started to create a document report.
What is a document report you might think?
Well, a document report is typically a report that you print or generate in pdf to send to a third party, like for example an invoice or a credit note to a customer or a purchase order confirmation to a vendor.
Typically a document report fetches information from multiple tables. In business central, a document, like a sales invoices, mainly stores information in two tables, Sales Invoice Header and Sales Invoice Line, which I will name the Header and the Line table.
The full-Monty of such a report would be report 206 Sales – Invoice or report 1306 Standard Sales – Invoice. In this blog post, I will explain how to get started, to create the dataset, based upon a Header and a Line table. In a later post I will then explain some more bells and whistles that are typically built in to those types of reports.
So, to get started, you can create a new report, name it: MyDocumentReport and add the following code:
In the dataset, I fetch the No. field from the Sales Invoice Header table, rename it to DocumentNo and add it in a data item with the name Header:
This is something I strongly recommend:
- Give your data item a proper and simple name like: Header
- Give your fields proper and simple names like: DocumentNo
This will make it easier to spot and find the fields in the layout of the report, as well in the RDLC and in the WORD layouts.
Now you can add more fields from the Header table as columns to the dataset, like for example:
Now we have three fields from the Sales Invoice Header table:
- Bill-to Customer No.
- Posting Date
You can do this by adding the property RDLCLayout to the report, and specify the path and filename:
If you now use the AL: Package command, or Ctrl + Shft + B, then the empty rdlc layout file is generated.