A question I get asked frequently is: Ho Do I Create a Report in VSCode, and to me more specific, How Do I Create the Layout, being an RDLC or Word layout?
The answer is that you need to create the report object as an .al file, then you create and export the layout(s) and reference them from within the .al file.
So let’s get started.
In VSCode create a new project, using the AL:Go command:
In your project, create a new file, for example: MyReport.al. In the Report.al file, use the treport snippet to create a report and then change the ID, Name and add fields and an option page, as in the following example:
In this example I’m using fields from the Customer table to build the dataset for MyReport. I have also added a variable HideDetails, which I have also added in the Request Page.
Now you need to be able to run the report. For this, I will make an extension to the existing Customer List Page. Create a new .al file, like the following example:
In the launch.json file I’m using the Customer List, page 22, as my startupObjectId:
Now, when you publish the project, using F5, the application opens, the Customer List displays, and the new action is available in the Actions:
And when you Run it the following happens:
The Request Page displays, with the HideDetails Boolean.
Now this report does not have a layout, so it makes no sense to Send or Preview it.
Now we need to create a layout. You can do this in the application.
Go to the page: Report Layout Selection and filter on your report Id or Name:
Our new report is found and as you can see, it does not have a report layout. We will now create one for it.
Select Actions, Custom Layouts:
Then select: New:
In the window that opens, I select RDLC:
An empty RDLC layout is now added to my report:
Select Export Layout, to save it. Save it in your AL project, for example in a subfolder called ReportLayouts:
Now open this file using Report Builder, for example via a right click and the open with Report Builder:
In ReportBuilder you can now modify the layout:
For example, add a Table to create a list layout:
Then save the file.
Now in the MyReport.AL file you need to reference the layout, for example as follows:
Now when you run the report, you see the following:
Similary I will now add a Word layout to the same report. So in the application, go back to the Report Layout Selection page and add a Word layout:
Then export it:
Now open it in Word:
You can now create the Word layout and save it in the ReportLayouts folder:
Then you need to reference the file in your report:
And as you might have noticed, I have set the Word layout as the DefaultLayout.
Now when you redeploy the extension and run the report, you see:
And voila, that’s all it takes to add an RDLC and WORD layout to a report, using the new development environment, VSCode…
Feel free to download the example here:
Ok, granted, it works, but I find this procedure really cumbersome. Cumbersome, that’s a polite way of saying, it’s ***! So I hope, one day, there will be an easier procedure to achieve this, one for which we can do it all in VSCode. But until then…