With the release of Dynamics NAV 2013 R2 developers now have more flexibility to design RDLC reports. Apart from working with report structure in Visual Studio, it is now possible to use Report Builder 3.0 as well.
To enable Report Builder, open the Dynamics NAV Development Environment, click Tools, and then Options. In the Options window, set Use Report Builder to a value of ‘Yes’: Click OK to close the window. Even if your environment does not have Visual Studio installed, you will still be able to design and develop reports for NAV 2013 R2.
In this article, we are going to apply some design tricks to add some non-native features that are frequently requested by customers.
Page N of M
This is one of the most common requirements to the report layout. Our task is to make reports show not just the sequential page number, but also the total number of pages. The tricky part here is that the requirement often relates to the document type of reports: invoices, orders, etc. These types of reports are printed as one per document, where one and the same document might contain more than one page. The difficulty comes when we print multiple document types, an example being 2 invoices. In this case, to show Page N of M, we need to perform the following tasks:
- Count the total number of pages for each invoice
- Reset the page number to 1 when the second invoice starts to print
Until the release of Microsoft Visual Studio 2012 and Microsoft Visual Studio 2013, this was accomplished in a roundabout way. It included pre-printing the report to count the group page number, and then printing the actual report with page numberings. Now, there is an easy and convenient way to perform this task. However, to do this we need to navigate into advanced group properties.
Open the Role-Tailored Client and navigate to Sales Quotes. Open a sample sales quote and make sure it contains multiple lines. This is needed to simulate printing more than one page of the report. In the Sales Quote window, click Print to preview our sales quote “as is”, and then choose the option to print to PDF in order to see the actual number of generated pages: Currently, the standard layout needs customization, as it just shows the page number: Notice that the total number of pages is 2. So, we would need to customize our report to show Page 1 of 2 and Page 2 of 2.
Open the Microsoft Dynamics NAV Development Environment. Click Tools, Object Designer. Select our report, 204, and click Design. In the Design mode, click View, C/AL Globals: Locate Text005 in the Text Constants tab and change its value to Page. Add a new text constant, Text50000, and set its value to %1 of %2, where %1 and %2 will act as placeholders for our actual page numbers.
Close the C/AL Globals window.
Add the Text50000 constant to the report dataset under the PageLoop section:
Save your work so far. Next, click View, then Layout. Now we need to make changes in the report layout.
On the report layout, in the Body section, select the list1_Detail_Group data region and click a small arrow to the right of it at the bottom section called Row Groups: Select Group Properties and in the properties window to the right, locate Group, Page Break properties. Set the ResetPageNumber to True value.
In the report Body section, locate a small table with 2 columns. Select the whole table and ensure its Hidden property is set to False.
Select the second column and in its Hidden property, type the following: Click OK to close the Expression window.
On the report header, locate the textbox, which holds the page value and type the following expression for it: Click OK, save and close the report layout, and then save and close the report in the NAV Development Environment. Now we can preview our work. Print the quote to PDF again and verify the Page N of M is printed:
Formatting the Text Placeholders
Another trick we are going to take a look at is printing the parts of the textbox in a different formatting style. For example, let us assume there is a need to print the following footer at the bottom of our report:
Cronus Danmark A/S
VAT Reg. No. 0934986242
We would like to have one textbox on the footer, so this means there will be a single expression corresponding to these 3 lines.
Open our report layout in designer again and left-click the area outside the report layout. Right-click to call the menu and select Add Page Footer:
On the page footer, place a centered textbox and add the following expression to it: What we will get is a single line of text with no bold or italics font where needed. To correct this, we will use HTML formatting, which will need to be enabled for our textbox. To do this, select the “Expr” text within the textbox and right-click on it and select Placeholder Properties:
In the Placeholder Properties window, select the HTML markup type and click OK: Now we can apply HTML tags to format our textbox text parts.
Open the textbox Expression window and change the expression as follows: Click OK, save and close the report designer. Now we can preview our changes: The report footer is printed as required, using a single textbox. This allows us to save space on the footer area during design and also simplifies the text alignment.
These are just a few basic tricks that allow for the easy addition of elements often demanded by customers. As we can see, with the new versions of Dynamics NAV and Visual Studio, they have become easier to develop and implement.