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…

 

21 Thoughts on “How Do I : Create a Report, and layout, in VSCode?

  1. No way… this cannot be for real. Someone needs to create a VSCode extension to make this easier…

    • That should be possible, since all of it is in existing NAV objects (creating and exporting the layouts…). At the moment I created a task in VSCode that runs Report Builder, that helps a little bit. I’m investigating how I could automate this process further…

  2. Considering that complicated reports require some back and forth with NAV logic changes and testing the layout, we really need a more integrated experience like we have currently. I can see this being useful if we can use this to make minor changes.
    We cannot expect wonders with release 12 though. Release 3 with NAV 2020 should be pretty good – lets hope they do not code name 2020 as Atlantis!

  3. Bill on August 8, 2017 at 00:20 said:

    Steven,
    I’m getting an error like the one in the following link: https://stackoverflow.com/questions/33554424/dynamics-nav-sql-server-report-builder-commandtext-property-has-not-been-ini

    So, I’m unable to test the report in ReportBuilder?
    I cannot run it and get results without going into NAV?

    • Hi Bill,
      No you can not run the report in Report Builder, you can only run it in Nav. The rdlc file only contains a description of the dataset, no data and no query. When Nav runs it, the data and layout are retrieved and sent to the report viewer which combines them to form the result.

  4. Pingback: How Do I : Create a Report, and layout, in VSCode? | PA

  5. Fleating83 on January 3, 2019 at 15:41 said:

    How do you put in two separate tables and in two tables? Like Order Header as well as it’s detail lines?

  6. Andrew on January 3, 2019 at 15:44 said:

    How do you include more than one table (like order and order lines)? Examples of filters on the data? Examples of how to run the report for a specific record (like order)?

  7. Pingback: How Do I : Create a Document Report, and layout, in VSCode? (part1) – think about IT

  8. Muhammad Ullah on March 14, 2019 at 07:30 said:

    Bundle of thanks Steven Renders. Very helpful blogs.Your blog solved my problem.

  9. Rajasekhar on April 29, 2019 at 09:22 said:

    Hi

    Is there any option to select Word layout or RDLC layout at Runtime for the same report.

    • Yes, you can use the Report Layout Selection page to do that.

      • Rajasekhar on April 29, 2019 at 12:48 said:

        Report layout selection is more likely for developers, but for end user is there any option to select which layout needs to print if report has both word and RDLC layouts when i run report from Menu directly not from Report layout selection?

        • Report layout selection is meant for end users, to create multiple layouts and then decide which one to use. Developers typically use development tools.
          To answer your question, no there’s no option to select the layout in the request page.
          You might be able to program something, if events are available. There are codeunits where the ‘standard’ looks to see which of the layouts is the default. You might extend that code. There’s however no documentation available, so you will have to figure it out by reverse engineering the code…

          • David Machanick on October 20, 2019 at 02:02 said:

            I have been studying the AL code for wave 2 for the sales invoice report, and the triggers for the first dataitems are at the end after all the other dataitems.
            Is this a structural requirement for reports in AL or just a sloppy C/AL to AL conversion?
            It makes document reports hard to follow, and the data triggers would be much easier to follow if they named the dataitem they were triggers for.

  10. Rachel Phillips on September 21, 2019 at 04:41 said:

    so you really still need report builder , vscode just shows text LOL, so vscode is not standalone support of report builder. typing code in a text editor does not make it an ide/compiler/builder

  11. Mark Anderson on October 19, 2019 at 15:04 said:

    Nice example. Done a lot of SSRS and a bit of AL (new to BC).

  12. Hans Freitag on November 21, 2019 at 08:58 said:

    Now in Version 15 Wave 2 you only need to Create the property “RDLCLayout = NameOfReport.rdl” to your Report in VSCode and automaticly will create the rdl File. Now it is not necessary to create it in the application.

    • Yes indeed, the procedure has simplified a lot. Since v14 (maybe even earlier) you indeed only need to specify the RDLCLayout and/or WORDLayout properties and the layout is created/updated when you package.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post Navigation