In most implementations, the focus is on customizing the Dynamics NAV application to meet the needs of the organization and sometimes also future needs. The effort that is required for reporting in general is often underestimated and unfortunately assigned to the least experienced consultants, who have to create/adapt document reports according to customer requests.
Personally, I believe reporting is one of the most important aspects of an implementation. It should therefore be given importance from the outset, in the analysis phase of the project. The kind of information you want to retrieve from your ERP system and the way you want to retrieve this information has a big impact on the implementation of the system. Doing this correctly at the beginning of a project can, and will, save a lot of time, money, and frustration. The unfortunate reality is that many partners and/or customers look at reporting first when they want to reduce the cost of an ERP implementation project.
This chapter is an introduction to creating reports in Dynamics NAV.
I will start by stating what a report is, and how standard Dynamics NAV includes all sorts of reports. Then, I will explain that report development is always done in three steps: creating the data model, then the layout and, last but not least, testing the report.
When creating the data model, I will guide the user and explain how to create a dataset, starting with a simple dataset consisting of one data item and then make it more complex by introducing multiple data items and explaining/demonstrating the effects on the dataset of the way you build data items.
I will also explain how to include captions and labels. Then, I will dive into Visual Studio and explain how to create the layout. I will also explain and demonstrate the difference between Visual Studio and Report Builder.
Reports have several purposes in Dynamics NAV. The purpose of a report is to print or visualize information from a database in an intuitive and structured way. For example, a report could be a list of customers, vendors or items, or a combination of customers and items sold.
Some reports are used to communicate with third parties. These reports are called document reports. Examples of document reports are sales invoices, credit memos, and so on. For every document in the application, a document report is also created.
Apart from printing information, some reports have no layout and are used only to process information. These reports are considered batch jobs or processing-only reports. You can compare them to code units but with the advantages of the report dataset designer and request page options.
From the users' point of view, everything starts with the Dynamics NAV application and their experience will vary depending on the Role Center they are assigned to. Dynamics NAV is all about the RoleTailored Client and the RoleTailored Client always opens with a Role Center page. A Role Center is like a dashboard. It is the starting page in Dynamics NAV and on it you will find the links to all the information you need.
This is an example of the Role Center for the Order Processor role:
Depending on the Role Center you are on, the ribbon will contain different reports. You can also access reports on other pages. For example, you can access reports in the menu at the top of the window on the Customer Card page:
When you go to Departments in the RTC, you can go to any department, for example, Sales & Marketing. When you click on Department, different categories appear in the content window:
These groups correspond to the groups defined in the menu item as defined in the MenuSuite designer for the Sales and Marketing menu. In each group, you will find links to reports:
The request page allows you to decide how you would like to view the report. At the top, there's a choice of Options. This contains options to change the type of visualization, or the way that the report behaves. Not all reports have an Options tab. The request page contains a tab where you can apply filters. In this example, you can apply a filter on specific fields, or on any other field from the underlying table of the report. If the table contains FlowFields, then you also have the option to limit the totals of the FlowFields. In other words, limiting totals means applying FlowFilters to the FlowFields.
You can then print or export the report to a specific format such as Word, PDF, or Excel with the buttons at the bottom of the request page, or you can schedule the report for it to run later.
The report viewer is launched from the report request page, but this is explained in a later section.
Any client computer, for viewing reports from the Microsoft Dynamics NAV client
The Microsoft Dynamics NAV Server, for using the
The computer running the development environment, for compiling reports
The report viewer is used when you preview the report if you are running a report from the Windows client. The report viewer supports user interaction and renders a report as an HTML page behind the scenes.
At the top of the report viewer there's a toolbar that provides navigation, search, export, and print functionality:
You can save a report as an Excel, PDF or Word file. The same report can have a different appearance and functionality, depending on the rendering format that you select. For example, reports that have links, document maps, and bookmarks might not work properly if the report is saved to a file. A report layout in a different file format might include additional pages or white space, depending on how items are aligned.
It's best to test the development with all render extensions (Preview, Print, PDF, Excel, and Word)
At runtime, users can use the print commands on the ReportViewer toolbar to open a Print dialog box, preview the report in print layout, and configure the page setup, prior to printing.
You can also print a report from within the report viewer but note that, if the function
CurrReport.PREVIEW is used in the code, the Print button will not be available in preview mode.
Who is the report intended for?
What is the purpose of the report?
How is the report going to be used?
Where should the information come from?
How should the information be visualized?
It doesn't matter what technology you are using, the development of a report always boils down to two things: the data model and the layout.
The data model is actually the most important phase in report development, because if you get it wrong or if you have to make fundamental changes to it, it usually means you will have to redo the layout. So, take your time to think about the data model thoroughly.
This means that you have to know what information is required in the layout and where it is from. Are you going to use one or more tables? Is the same information available in different tables, in that case, which one are you going to use?
Remember, in Dynamics NAV, information travels from the master tables, via documents and/or journals, towards ledger entries and posted document tables. Some information is copied from one table to another, in order to keep track of history or changes.
Make a list of all the tables that contain the information and then decide which ones you are going to use. In real life, this probably means you will have to consult an expert or a business user and explain that the information they require resides in multiple tables, so they can make an informed decision as to which table you should use in the report.
Ledgers or Posted Documents?
Dynamics NAV allows posted documents to be deleted after they have been printed. So, if confronted with the choice of using ledger entry tables or posted document tables as data sources for a non-document report, I recommend using ledger entries.
Once you have defined which tables you are going to use, you will need to think about the relations between the tables, how you are going to link the tables, and also in what order? The order will have an influence on the performance of the report, but also on the kind of information that might be missing.
For example, if you are asked to create a report to display inventory by location, the questions you should ask are:
What is inventory, is it the sum of the quantities in the item ledger entry table?
What quantity field should I use: Quantity, Remaining Quantity…?
What is a location? Is it the Location Code field in the Location table or something else?
Do I need to include items for which there is no inventory?
Do I need to include locations for which there is no inventory?
Do I have to display the item number or also the description?
Should I include any translations, substitutions, variants, or cross-references?
The answers to these questions will define which tables and fields you are going to include in the data model and in which order you are going to iterate over them.
A good idea is to make a draft drawing of the layout of the report you want to create on a piece of paper. Write down the fields that need to be visible on the report and then find out which table they are from. After that, if there are multiple tables, find out how the tables are related and write that down. Having an entity relationship (ER) model helps a lot here, especially in a customized database.
In this way, when you open the designer, you already know what you need to do. Both novice and experienced developers make the mistake of not thinking before they begin. It can then get confusing very quickly.
A good suggestion is to have a requirements session with the user, during which you can create a mock-up of the report. Then you can define each field, column, grouping, sorting and printing option. Based on this session, you can then create the data model for the report. This mock-up is also referred to as a format design document.
Although the data model is important for the reasons I just explained, the layout of the report determines how the user will perceive it. So, if the layout is not easy to interpret, or if you can't see the wood from the trees, however cleverly you construct the data model, the report is not going to be used.
There are many out of the box reports in the Dynamics NAV application and most of them are never used. One of the reasons is that they have an inadequate layout.
How do I visualize the information such that the report clearly reveals its intention and the user quickly finds what he or she is looking for? That's the most important question to ask when creating the layout.
Creating a report is not difficult, but making it easy to understand, so that you can spot trends and learn from your data, takes some consideration. The main goal of a report is to communicate information clearly and effectively, for example, graphically. A report needs to create insights by communicating its key points in an intuitive way.
Using the example of the inventory by location report, you might consider how you are going to visualise the inventory. Are you going to display a number, or a data bar? Is it important to include a key performance indicator, for example compare the current inventory with the reorder point (or some other important value)? Or are we using items with an expiry date? If so, do items close to expiry need a different color? Then, in what order are you going to display the locations and items?
Testing is a phase that is often neglected, for different reasons. The most frequent excuse for the lack of tests is not having enough time. That might actually be true when you are developing the report, but, in the end, when users complain about bugs and missing functionality, you will wish you had tested more thoroughly.
Of course, this needs to be specified in your report's design document. Its test criteria should mention which formats the report needs to be tested in.
Another reason tests are usually dismissed or poorly carried out is a lack of understanding of the business case. How is the user going to use the report? Is all the information on there, and is it correct? As a developer in the NAV world, you have to put yourself in the shoes of the user. Only then will you truly understand if what you developed is ready or not.
Using the example of the inventory by location report, a test verifies if the inventory is correct and corresponds to the inventory on the item card. Are there any locations or items missing from the report?
The development of reports in Dynamics NAV is done with different tools. You use the report dataset designer to create the dataset, which opens from the object designer in the Dynamics NAV Development Environment. You can choose to use either Visual Studio or Report Builder to create the layout.
Depending on your version of Dynamics NAV you will have to use different versions of Visual Studio.
In the development environment, on the Tools menu, choose Object Designer.
In Object Designer, choose Report, and then choose New.
There are two types of report layouts: client report definition (RDLC) layouts and Word layouts. To create an RDLC layout, you use Visual Studio Report Designer or Report Builder from the Microsoft Dynamics NAV Development Environment.
The RDLC layout is the most flexible. By this, I mean that, from a technical point of view, you have the ability to use expressions to determine how and when data should be visualized. The Word layout is restrictive and imposes limitations on the way you create the dataset.
In this chapter, I will focus on the RDLC layout. The Word layout is explained in Chapter 8, Word Report Layouts.
A report can have multiple layouts. In the development environment, a report can have one RDLC layout and one Word layout. These are the built-in layouts, because they are a part of the report object and are stored inside the report object. You can see this when you export the report object to a text file, as the RDLC and Word layout are then included.
A user can also create a custom layout with the Dynamics NAV application, which is based on the built-in layout. The idea is that a user can customize the built-in layouts according to their needs. In this way, a user can switch between different layouts for the same report. These custom layouts are not stored in the report object, they are stored in a separate table: 9650 report layouts.
In a multi-tenant Microsoft Dynamics NAV deployment, the built-in report layouts are stored in the application database because they are part of the report objects. Therefore, built-in report layouts are available to all tenants. Custom report layouts are stored in the business data database, therefore they are specific to the tenant. This enables you to create separate report layouts for each tenant.
The data model of a report is designed in the report dataset designer and will become the dataset for the layout. The runtime dataset is flat and is generated from the data items (tables). The layout will be rendered on top of the dataset.
Flat means that the dataset consists of rows and columns. For example, when you combine two tables that have a one-to-many relationship, such as the sales header and sales line, the dataset will consist of the columns from both tables and a row for every line, in which the columns from the header table are repeated. So, at runtime, the dataset looks different when compared to the definition of the dataset in the report dataset designer, where data items are indented. I will explain in more detail later in this chapter how the dataset is flattened and columns from different data items are combined.
The following screenshot is the dataset of the Report 1305 Mini Sales - Order. As you can see, it contains many tables and columns:
As you can see, the dataset at runtime consists of rows and columns. There is a column for every column in the dataset designer, and a row for every record from the data items. This is referred to as a flat dataset, as against the data items, which are indented.
To visualize the dataset of a report at runtime use Ctrl + Alt + F1, or About This Report, as shown in the following screenshot:
When you select About This Report, the system tells you that you have to run the report again to see the data. Actually, you have to enable this feature before you can see the dataset. This means, of course, that you have to run your report twice, just to be able to see the contents of the dataset.
The information in the About This Report page can also be exported to Microsoft Word or Excel or to an e-mail in Microsoft Outlook. A user can then forward this information to the helpdesk or whoever is providing support.
If you click on the About This Report feature in the request page of the report, then it is also enabled. After that, at runtime, you can click on About This Report and the dataset will contain data. In this way, you don't have to run the report twice to be able to see the dataset.
A column can be a field in a table, but it can also be an expression, a variable or a text constant.
Let's start with an example and create an item list report. The idea is to display a list of items, so I will use the Item table as my data item and I will add the number, description and inventory as columns.
In the dataset designer, add a Data Type DataItem and Data Source Item line, then use the field menu button to select the fields from the Item table:
The Field Menu allows you to select any of the data item fields and add them to the report without having to type in the Name of the field.
In the Field Menu window, select one or more fields that you want to add to the report dataset. Select multiple fields by holding down the Shift key or the Ctrl key. Choose the OK button to add the selected fields to the dataset.
All names in the Name column must be unique and Common Language Specification (CLS) compliant. You will notice that, when using the Field Menu, the field name consists of the field name, an underscore, and the data item name.
More information about the Common Language Specification is available in the MSDN Library at https://msdn.microsoft.com/en-us/library/12a7a7h3.aspx.
After you have selected the data items and columns you want to add in the dataset, open the properties window. Here you can set the data item and field properties.
Use Shift + F4 or the property button at the top to open the properties. When you select a data item or a field, the property window displays the properties of the selected data item or field. When you go to the last line in the dataset designer, referred to as the first empty line, the property window displays the report properties.
The following image shows the properties of a data item and of a field:
You can also include a variable in the report dataset. Define the variable in C/AL Globals and then add it by typing in its name or using the assist-edit button in the data source column where you can select it from the C/AL Symbol Menu:
Item.Description + '-' + Item.No_
-("Line Amount" - "Inv. Discount Amount" - "Amount Including VAT")
You are not only going to display data in the report layout but also field names and textual information. These names and text will be displayed in the user's own language, since Dynamics NAV is a multilanguage application. You can therefore use captions and labels when you design the dataset. Captions and labels are sent as parameters to the report layout. They are not actually included in the dataset, because their value is the same for every record and we don't want this information to repeat because that would increase the size of the dataset unnecessarily.
To include a caption:
Select the row in the dataset.
Open the properties window (Shift + F4).
Enter Yes in the IncludeCaption property.
Alternatively, use the IncludeCaption checkbox in the report dataset designer:
You can only use the IncludeCaption property on table fields. For other fields, you can define a label.
To include a label:
Go to View, Labels to open the Report Label Designer.
Add a new label in the Report Label Designer by entering a Name and a Caption.
Then, in the Label properties, use the CaptionML property to translate the label into other languages.
Alternatively, you can use the assist-edit button to open the label Multilanguage Editor:
How to see the properties
To see the properties of a column or data item, you have to first select it. Make sure it is selected by clicking on it with your mouse. Then, you can click on the properties button at the top of the screen, or press Shift and the F4 function key. Now, the property window opens and displays the appropriate properties.
Captions are sent as parameters and in the language of the user. In some cases, for example in document reports, you may want the captions to be in the language of the recipient, not in the language of the user. To do that, you use the
FIELDCAPTION function, and add the caption to the dataset as an extra column. Then, you can determine the language via C/AL code.
Keep in mind that adding captions to the dataset with
FIELDCAPTION increases the size of the dataset, so only do this when it is really necessary. In previous versions of Dynamics NAV, captions were added by default in the dataset, so using
IncludeCaption and labels is a performance improvement.
An example of the use of
FIELDCAPTION can be found in most document reports:
Sales: Credit Memo
Examples of the
FIELDCAPTION function are shown in the following screenshot:
At runtime, a report dataset consists of rows and columns. If you only have one data item, then the columns in the dataset designer become the columns of the runtime dataset and the rows from the data item (or table) become the rows in the dataset. In this situation, the runtime dataset looks the same as when you simply run the table.
If you combine multiple data items, then the data items at design time can be indented, or not, and this results in a different dataset at runtime. Since the runtime dataset is two dimensional, consisting of rows and columns, information is repeated over multiple rows.
In this section, I will explain and demonstrate how the runtime, flat, dataset is generated, using indented or non-indented data items.
Using multiple data items in a report is a common pattern in most reports and understanding how the multi-data-item dataset at design time is converted into the flat two-dimensional dataset at runtime is very important. Understanding this process is, in my opinion, the most important part of RDLC report development, because it determines how you build the layout and which filters you need to apply in the RDLC layout.
As an example, let's start with a dataset that consists of two data items, Vendor and Customer:
When we run this report and display the dataset with the About This Report feature, it shows this:
When the report processes the data items it starts with the first one (on top), which is
Vendor. For all vendors, it fetches their
Name and adds it to the dataset. The customer columns remain empty. Then, after the
Vendor data item has been completely processed, the system starts with the
Customer data item and does the same. The result sets of the two data items then follow each other in the dataset, stuck together.
Now imagine that I need to create a request page for this report to include an option to display details. Then, I would create a variable
HideDetails, add it to the request page, and also add it to the dataset. If I added this variable to the dataset as an extra column, then we would have a problem. Are we going to add it to the Customer or Vendor data item? If we add it to the customer data item, it will be available at runtime, but not in the vendor rows. Now, as this is a variable that contains a constant value, we only need it once and there's no point in repeating its value on every row, because that would increase the size of the dataset and so decrease performance.
The solution is to include an extra data item that will only add one row to the dataset. To do this, you can use the integer table, as shown in the following screenshot:
The integer data item adds one row at the end of the dataset and this contains the value of the
SORTING(Number) WHERE(Number=CONST(1)) in the
DataItemTableView property of the
Integer data item makes sure that the outer data item produces exactly one row from the
Use the following expression to retrieve this value in the layout of the report:
Unless you add the integer data item as the first data item in the report dataset designer, the row is added to the beginning and the expression becomes this:
Remember that we have an extra row in the dataset containing our variable
HideDetails. This row should be filtered out in the tables in the layout that display the Vendors and Customers.
An example of this report is available in the object: Packt - CH01-2
Using an integer data item, and filtering it to add one or more rows in the dataset, is a common pattern in report design. Instead of filtering on a constant value, you can also set the filter on the integer data item via the C/AL code in the integer data item
OnPreDataItem trigger. In that way, you can set it at runtime, depending on an option in the request page. In document reports, this is usually how the
NoOfCopies option is implemented. I will come back to this pattern in the Chapter 5, Document Reports.
Let's create a report with a dataset that contains two data items as an example: Customer and Customer Ledger Entry.
In document reports, this pattern is applied a lot, because, in a document report, we have many data items that need to be visualized in different tables (or sections) of the report.
The Customer Ledger Entry needs to be linked to the Customer, so for each customer we can see their individual entries. Linking data items is done by indenting them in the report dataset designer and then, in the indented data item setting, the link fields in the property
DataItemLink, as follows:
Then, when you run the report, the dataset becomes:
Customers that don't have ledger entries are shown, but the ledger entry columns are empty. Customers that have ledger entries are shown and, for every ledger entry, there's a row in the resulting dataset.
As you can see, if a customer has multiple ledger entries, then, for every ledger, a row is added to the dataset and the columns for the customers are repeated on each of these rows. This is called the flattening of the dataset, the columns of the parent record are repeated for every child record.
To filter out customers that don't have ledger entries, you can use the
PrintOnlyIfDetail property. You need to set this on the top data item, in this example, the
PrintOnlyIfDetails specifies whether to print data in a report for the parent data item when the child data item does not generate any output. If there are more than two data items, then the report iterates through each parent child relationship in the same way.
If you are going to create a layout for this dataset and you want to see the ledger entries per customer, you do this by creating a group in the table and grouping on
This is a very common design for the datasets in Dynamics NAV reports. It is used with header and line tables, master and ledger tables, and also in document reports.
If you omit the DataItemLink and DataItemLinkReference between the Customer and Customer Ledger Entry table, which effectively disconnects the two tables, then the resulting dataset is much larger, since it includes all possible combinations of headers and lines, with absolutely no regard to their possible table relations.
When using multiple data items with indentation, you can also apply the technique of including an integer data item. In that case, investigate the resulting dataset before you create the report layout because, depending on the result, you might want to move the integer data item to the top or bottom to get a better dataset.
A report, like other objects in Dynamics NAV, contains triggers. These triggers are fired when specific events happen and allow you, as a developer, to have code executed at those moments. In this section, I will explain the different triggers and in what order they are fired.
When you run any report, the OnInitReport trigger is called first. This trigger performs any processing that is necessary before the report is run, and so before any data is read, and before the request page is shown to the user.
Next, the request page for the report is run, if it is defined. Here, you select the options that you want for this report.
If you decide to continue, the OnPreReport trigger is called. At this point, no data has yet been processed. You can use this trigger to initialize variables or fetch information from the database via C/AL code. The
Company Information table is usually queried in this trigger to retrieve company information like the name, VAT number, company logo, and so on.
When the OnPreReport trigger has been executed, the first data item is processed. When the first data item has been processed, the next data item, if there is any, is processed in the same way.
When there are no more data items, the OnPostReport trigger is called to do any necessary post-processing.
The following is a visual representation of the report execution flow:
The OnPostDataItem trigger is executed after the data item has been processed, meaning after all records have been fetched from the table. This trigger usually contains no code, or just code to clean up variables or filters.
In between the OnPre and OnPost DataItem triggers, the data is processed on a record by record basis. The OnAfterGetRecord trigger is executed after a record is fetched from the table, but before it is added to the dataset.
Understanding the flow of report triggers and data item triggers is crucial when deciding where to put C/AL code. C/AL code should not be executed when it is not necessary. For example, if you can choose between the OnAfterGetRecord trigger and the OnPreDataItem trigger, you should choose the OnPreDateItem trigger. This is because the OnAfterGetRecord trigger will execute for every single record that is retrieved from the database.
A processing-only report is a report that does not print but just processes data or C/AL code as in batch processes that require user input. Processing table data is not limited to processing-only reports. Reports that print can also change records. This section applies to those reports as well.
It is possible to specify a report to be "Processing Only" by changing the
ProcessingOnly property of the Report object. The report functions as it is supposed to (processing data items), but it does not generate any printed output.
ProcessingOnly property is set, the request page for the report changes slightly, as the Print and Preview buttons are replaced with an OK button. The Cancel and Help buttons remain unchanged. When the
ProcessingOnly property is set, you cannot create a layout.
If you want to remove the layout from a report set the
ProcessingOnly property to
yes. You will get a prompt that the layout will be removed. Then, set the
ProcessingOnly property back to
There are advantages to using a report to process data rather than a code unit:
The request page functionality that allows the user to select options and filters for data items is readily available in a report, but difficult to program in a code unit.
Using the report designer features ensures consistency. Instead of writing code to open tables and retrieving records, report data items can be used.
In the Dynamics NAV development environment you can set the Use Report Builder option, via Tools/Options. If set to
No, then the system will use Visual Studio to create the report layout, otherwise Report Builder will be used.
By default, the option is set to
No, even when Visual Studio is not installed. You have to manually set this to
yes if you want to use Report Builder.
Report Builder is (normally) installed together with Dynamics NAV when you install the development environment. Visual Studio has to be installed separately. Report Builder is free and can be downloaded from the Microsoft website. To be able to create report layouts with Visual Studio in Dynamics NAV 2013, you need at least the Professional edition of Visual Studio, which is not free.
As from Dynamics NAV 2015 you can use the Visual Studio Community Edition 2013, which is free and can be downloaded from https://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx.
I will start with the report Packt - CH01-1, which contains a data item for the integer table, and I will create a simple layout to display an item list.
From the report dataset designer, click on View, Layout to open Report Builder:
Built-in Fields: The built in fields can be considered as constants or variables. They are not a part of the dataset and can be used in the layout, in textboxes or in expressions.
Parameters: Parameters contain the labels and captions that were added via the
IncludeCaptionproperty on a column, or via the label designer.
Images: Images can be imported into the report layout as embedded images.
Data Sources: In Dynamics NAV RDLC reports, there is always exactly one data source. At runtime it links to the report dataset, generated by the report dataset designer.
Datasets: In Dynamics NAV RDLC reports, there is always exactly one dataset. It has the name
Dataset_Resultand contains the columns that were added in the report dataset designer.
At the top you can see the ribbon. It contains three sections:
Home: Here you can see formatting toolbars and buttons. You can use them to format the layout of textboxes in your report.
View: Here you can customize the Report Builder look and view. You can disable or enable Report Data, Grouping, Properties and Ruler.
At the bottom, you can see the Grouping pane. It contains Row and Column groups. You can use them when you want to add grouping to your report layout.
On the right you can see the Properties. Depending on what you select in the layout, you can see and edit its properties.
In the Insert tab in the ribbon, click on Insert, then Table, and then Table Wizard.
In the Choose a Dataset window select Dataset_Result and click on Next.
In the Arrange fields window you can now see the columns on the left. You can drag them to the right and put them into Values, Column Groups and/or Row groups. Let's drag the fields into Values:
In the Choose the Layout window, you can select grouping and totaling options, but only if you added a row and/or column group in the previous window. Click on Next.
In the Choose a Style window, you can select a style template. Click on Finish.
The wizard has ended and it has added a table to the body of the report:
Now, we are going to save and test the layout.
As you can deduce from this message, Dynamics NAV has generated a
report.rdlc file and opened it in Report Builder. Then, we made changes to it, via the wizard. Now, it's asking us to save our modifications. This
report.rdlc file will then be imported back into the report dataset designer. This happens when you click on a line in the report dataset designer:
Click on Yes (if you click on No the changes are not imported and will be lost.) After you click on Yes, the system will parse the
report.rdlc file for errors. Some errors will be detected at this stage. Now you need to save the layout in the report object in the Dynamics NAV database. Click on File, Save (or Ctrl + S). When you save it, with the compile option checked, the system will parse the complete report and some errors might be detected.
Now run the report via File, Run (or Ctrl + R). The request page opens. Click on Preview:
You don't have to close Report Builder if you know in advance the layout is not ready and you only want to test or preview it. In that case, save the layout in Report Builder and minimize Report Builder, don't close it. Then, click on a data item to import the layout, confirm and save, and run the report. If you need to make more changes to the layout, simply return to Report Builder, make your changes and follow the same steps to import your changes back into the report dataset designer.
I will start with the Item List report I created with Report Builder, but first, I will remove that layout by setting the
processingonly property to
yes. The following message is displayed:
After confirming and deleting the current layout, don't forget to set the property back to
Next, click on View, Layout to open Visual Studio:
The Report Data window needs to be opened manually by selecting View, Report Data (or Ctrl + Alt + D). You will need to do this every time you open Visual Studio.
If Report Data is not available in the View window, then click somewhere in the body of the report to make it available in the View menu. Visual Studio automatically populates the toolbars with options depending on what you have selected in the layout.
To create a table layout, I will use the Toolbox. To open the Toolbox click on View, Toolbox:
To populate the table I will use the captions on the first row, which is the header row, and I will use the value fields from the dataset. From the parameters, drag the parameter into the textbox on the header row. Then, in the corresponding textbox on the detail row, click on the drop-down box to select the value:
There are many other ways of doing this, but I find this the easiest. Otherwise sometimes Visual Studio might create extra columns.
Repeat this process for all the columns. Then select the first row via its handle and make it bold. Next, we need to save our layout in Visual Studio, minimize it, and then go back into the report dataset designer and import it into the report object, just like we did with Report Builder. Then you can save and run the report to see the result.
In Visual Studio, you can change the layout of the report designer. You can move around the report data, properties and other sections. You can enable and disable toolbars, and so on. It's much more flexible than the report builder.
There is also the Format menu:
This menu contains many formatting options. They are especially useful when you need to align textboxes, for example in a document report.
There's also the Solution Explorer:
It contains the complete solution. Be careful, because only the
report.rdlc file is imported into the report object. Any changes to the other items in the Solution Explorer are not saved. One advantage is that we can add extra template reports in the Solution Explorer. These templates can contain tables, lists, and matrices which you can pre-format and then copy and paste into your report layout. I will explain later how you can create and include these templates.
I would like to point out that there is a big difference between what you see and experience when you print an enhanced report onscreen and what you see and expect, when you actually print it on paper, or export it to Excel, Word or PDF.
When you run a report in the report viewer then it is fully functional. What I mean by this is that all interactive features the report contains are available to the end user. An enhanced report can, for example, contain hyperlink actions, expand/collapse functionality, drilldowns, and so on. When the user prints the report on paper, that interactivity is lost. If the main usage of a report is to print it, as document reports usually are, then don't spend much time adding interactivity to the report, because it will almost never be used and so will not be a very good return on investment.
Don't enhance too much
From personal experience, I have seen many customers migrate towards enhanced reports as they are eager to implement a lot of interactive features in reports, and because it looks like a good thing to do. It is possible, so why not implement it?
Remember that adding functionality to reports should be based upon business requirements and not only because it looks nice. The more functionality you implement in reports, the more difficult it will be to maintain these reports.
Apart from the functional reasons online reports are better than printed reports, there's also the financial aspect. By using online reports, you will spend less on paper, ink, storage, binding, and distribution.
The ability of RDLC to export a report to PDF and/or Excel can help, but you must also remember that not all of the interactive features will still work in PDF and/or Excel. For example, drill down is available in Excel, but not in the PDF format.
Some reports look very different in online mode as compared to being printed on paper or exported to Excel or PDF. For example, totals at the bottom, page breaks, running totals, headers, and footers are items to pay attention to. That's why it's very important to test all of these scenarios and explain to the end user how to use the report.
Even when the user specifically asks for only Excel and PDF it is important to test other renderings and run any issues that you see by the users, to make sure they don't come back later if they see a problem with the other rendering options.
Microsoft has published design guidelines you can follow when you create a layout for a report. This is especially important when you develop document and list reports. By following these guidelines, you can make sure that your reports are:
Simple and clean
Easy to scan and read
Professional and consistent
Applying these guidelines has the advantage that you can use a minimum set of rules, by using the default formatting options available in Visual Studio. You can also create report layout templates that you can apply by report type so that all your reports have a standard look and feel and give a consistent user experience.
Microsoft followed these guidelines, in some reports, when they developed the report layouts in Dynamics NAV 2013. In most implementations of Dynamics NAV, document reports are customized and this process can be time-consuming. The idea was to provide layouts that could be used out of the box in real life. I will leave it up to you to decide if this is true.
Before a report is run in the Windows client, a request page is shown. Here, you can enter filters, define sorting, and specify options for the report. A request page is automatically created when you create a report. The Request Options Page tab has to be created by the report developer.
To design the request page options tab, click on View, Request Page in the report dataset designer. This opens the request page designer. It is actually a page designer in which we usually create an options
Here's an example:
Create a new report in the object designer.
Create the data model in the report dataset designer
Add a data item in the data item designer.
Add fields from the data item as columns in the report dataset designer.
Create the report layout:
Use the View/Layout menu to open the layout and create the RDLC file.
Make changes to the layout, and add new controls from the toolbox.
Save the changes in the layout.
Go back to the report dataset designer and click on one of the data items.
Answer Yes to importing the RDLC file.
Test the report:
Save your report.
Run your report.
In this chapter, we created our first report, using Report Builder and the Visual Studio report designer. The chapter provided you with a good understanding of the steps required to get started when creating report layouts.
Remember that developing a report can be broken down into different phases: the data model, the layout and testing.
We can conclude that the RDLC layout is a very big step forward in regards to report design functionality. It has enormous potential and added value and features that we can now use and apply when designing reports in Dynamics NAV.
The choice between Report Builder and Visual Studio depends on your experience. If you are a less experienced developer and you want to make use of wizards to create a report layout, then Report Builder is a good starting point. Visual Studio has a lot more features and is much more flexible. So, as you go along, you will probably favor Visual Studio over Report Builder or, to get the best of both worlds, you can combine the two. Of course, Report Builder is free and Visual Studio is not, so sometimes your budget will determine which one you are going to use, depending if you are using Dynamics NAV 2013 or 2015. But Visual Studio has so much added value that it will have a great return on investment.
In the next chapter, we will explore the Tablix data region. I will explain what a Tablix is and how it can be used to create a list, table or matrix.
Last, but not least, we will learn about grouping, sorting and formatting report items.