In Microsoft Dynamics NAV 2013, creating new reports is divided into the following phases:
- Defining the dataset on which the report is
- Designing and editing the visual layout of
the report by using Visual Studio Report Designer.
About This Walkthrough
This walkthrough provides an overview of how to create a report that is based on one table with Microsoft Dynamics NAV and design this report using Visual Studio Report Designer. This walkthrough illustrates the following tasks:
- Create a report in Microsoft Dynamics
- Apply sorting criteria and filters on the
report in Microsoft Dynamics NAV.
- Design the layout of the report in Visual
To complete this walkthrough, you will need:
- Microsoft Dynamics NAV 2013 with a developer
- The CRONUS International Ltd. demo data
- Visual Studio. For more information about
which version of Visual Studio you need, see System Requirements for Microsoft
Dynamics NAV 2013. This walkthrough uses Visual Studio 2010 SP1
Defining the Dataset
When you create a new report, you must define where the data that the report will display should come from. You define the dataset in Microsoft Dynamics NAV Report Dataset Designer.
To define the dataset
In the Microsoft Dynamics NAV Development Environment, on the Tools menu, choose Object Designer.
In Object Designer, choose Report, and then choose the New button to open the Report Dataset Designer.
In the first row, in the Data Source field, choose the AssistEdit button. In the Table List window, select table 18, Customer, and then choose the OK button.
In Report Dataset Designer, on the first row, verify that the Data Type column is set to DataItem.
On the View menu, choose Field Menu.
In the Field Menu window, select the No., Name, Address, Phone No., and Country/Region Code fields, and then choose the OK button.
You can select multiple items by holding down the Ctrl key while you select.
At the prompt, choose Yes to add the selected fields.
On the File menu, choose Save As.
In the Save As dialog box, in the ID field, enter 55551, and in the Name text box, enter Customer List.
Make sure the Compile check box is selected and choose the OK button.
Applying Sorting Criteria and Filters
Next, you will set the sorting criteria and filters that you want to use in the report. This report will sort the customers in ascending order by customer number. You will also provide filters on the request page that will enable users to filter the data based on the No. and Country/Region code.
To set the report properties
In Report Dataset Designer, select the DataItem row.
On the View menu, choose Properties.
In the Properties window, select the DataItemTableView property, and in the Value field, choose the drop-down arrow to open the Table View property window.
In the Key field, select the No. field, and then choose the OK button.
In the Order drop-down list, select Ascending, and then choose the OK button.
You will now add filters to the request page that will enable users to filter the data based on the No. or Country/Region Code, or both by default.
In the Properties window, select the ReqFilterFields property, and in the Value field, choose the AssistEdit button to open the Field List property window.
In the Field List window, in the first row, choose the AssistEdit button to open the Customer-Field List window. Select the No. field, and then choose the OK button.
In the second row, choose the AssistEdit button and select the Country/Region Code field, and then choose the OK button.
On the File menu, choose Save.
In the Save window, make sure Compile is selected, and then choose the OK button.
Close the Properties window.
Designing the Report Layout
After you have saved and compiled the report in Report Dataset Designer, you must design the layout in Visual Studio. For this report, you will display all the fields that you selected, and display the company name in a larger font and set it to bold. You will also display the date, time, and username of the person who runs the report.
To design the layout of the report
On the View menu, choose Layout. The report opens in Visual Studio. The report layout is empty.
In Visual Studio, on the View menu, choose Toolbox to open the toolbox.
From the Toolbox, drag a Table control to the report layout.
The table has only three columns, therefore, you will add two more columns to accommodate all the fields in the dataset.
Select the third column, open the shortcut menu, choose Insert Column, and then choose Right to add a new column. Repeat to add another column.
The next step is to populate the table with the data from the dataset.
To populate the list with data from the dataset
On the View menu, choose Report Data.
In the Report Data window, under DataSource, and under DataSet_Result, drag fields to the Data section of the report layout. On the second row of the table, drag the following fields.
From the Toolbox, drag three text boxes and put them above the table in the report designer. These text boxes will display the date and time, the username, and the company name.
Select the first text box, open the shortcut menu, and then choose Expression to open the Expression Properties window.
Under Category, choose Built-in Fields, double-click ExecutionTime, and then choose the OK button. This expression displays the time the report was executed.
Select the second text box, open the shortcut menu, and then choose Expression to open the Expression Properties window.
Under Category, choose Built-in Fields, double-click UserID, and then choose the OK button. This expression displays the user ID of the user who runs the report.
Select the third text box, open the shortcut menu, and then choose Text Box Properties to open the Text Box Properties window.
On the General tab, in the Value drop-down list, enter the company name. For this walkthrough, you can enter CRONUS International Ltd..
In the Textbox Properties window, on the Font tab, set the font size to a larger font, such as 14pt, and under Style, select Bold, and then choose the OK button.
You will format the text boxes for the field captions in the table to display in bold font.
On the report layout, resize the three text boxes to an appropriate size.
Select the No Customer caption text box, and choose Text Box Properties to open the properties window.
On the General tab, in the Value drop-down list, change the value to Customer No.
On the Font tab, and under Style, select Bold, and then choose the OK button.
Set the remaining caption text boxes to bold.
Save the Report.rdlc file and close Visual Studio.
Loading the Design Changes from Visual Studio and Running the Report
Now you will load the changes that you made in Visual Studio to Microsoft Dynamics NAV to apply the changes to the Customer List report.
To load the design changes from Visual Studio and run the report
Close Report Dataset Designer. A message informs you that the .rdlc file for this report has changed and asks if you want to load the changes. Choose Yes to save the changes in the database.
In the Save Changes window, make sure Compile is selected, and then choose Yes to save the report.
In Object Designer, select the report (55551) and choose Run. The request page is displayed.
In the request page, on the Customer tab, set the Country/Region Code filter to a country code and choose Preview to view the report. The report displays all the customers in the country/region code you selected.
You can filter the report by No. or Country/Region Code or both.
- Now you have created a report that lists
customers by customer number or country/region code, and you have
added changes to the report layout in Visual Studio. The next step
is to add the customer list report to a page in the RoleTailored
client from where it can be run. For more information, see How to: Make a Report
Available from a Page.