Walkthrough: Creating a Report with Parameters
Important
This content is archived and is not being updated. For the latest documentation, see Microsoft Dynamics 365 product documentation. For the latest release plans, see Dynamics 365 and Microsoft Power Platform release plans.
Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
In this walkthrough, you will create a report that displays customer data. You will add parameters to the report to allow users to filter the data that displays in the report.
This walkthrough illustrates the following tasks:
Defining a query
Creating a reporting project
Creating a report
Adding parameters to a report
Prerequisites
To complete this walkthrough, you will need:
Microsoft Dynamics AX with sample data
Note
This walkthrough uses the CustTable table. In order to view data in the report, this table must contain data.
Microsoft Visual Studio 2010
Microsoft Visual Studio tools for Microsoft Dynamics AX
Defining a Query
There are several ways to retrieve data for reports. In this walkthrough, you will use a query that is defined within the Microsoft Dynamics AX development workspace. The following procedure explains how to define the query that will retrieve data for the report.
To define a query
Open the Microsoft Dynamics AX development workspace.
In the AOT, right-click the Queries node, and then click New Query.
Right-click the node for the query, click Rename, and then type CustomerList.
Expand the node for the CustomerList query.
In the AOT, right-click the Data Dictionary node, and then click Open New Window.
In the new window, expand the Tables node.
Locate the CustTable table and drag it onto the Data Sources node for the CustomerList query.
Expand the CustomerList > Data Sources > CustTable_1 and then click Fields. In the Properties window, set the Dynamic property to Yes.
Save the query.
Creating a Reporting Project
Next, you will create a reporting project in Microsoft Visual Studio. In this walkthrough, you will use the Report Model template.
To create a reporting project
Open Microsoft Visual Studio.
On the File menu, point to New, and then click Project. The New Project dialog box displays.
In the Installed Templates pane, click the Microsoft Dynamics AX node, and in the Templates pane, click Report Model.
In the Name box, type SampleCustomerListReport, and in the Location box, type a location.
Click OK.
Creating a Report
Now that you have created a reporting project, you are ready to create the report. The following procedure explains how to create the report.
To create a report
In Solution Editor, right-click the SampleCustomerListReport project, point to Add, and then click Report.
In Model Editor, edit the Name property for the report and type CustomerList.
Right-click the Datasets node, and then click Add Dataset.
Select the node for the dataset.
In the Properties window, specify the following values.
Property
Value
Data Source
Dynamics AX
Data Source Type
Query
Default Layout
Table
Dynamic Filters
False
Name
Customers
Query
Click the ellipsis button (…). A dialog box displays where you can select a query that is defined in the AOT and identify the fields that you want to use.
Select the CustomerList query and then click Next.
In the Select Fields tab, expand the All Fields node and then select the AccountNum field.
Expand the All Display Methods node and select the address, name, phone and telefax methods.
Click OK.
In Model Editor, select the Customers node and drag it onto the Designs node. An auto design named AutoDesign1 is created for the report.
Select the AutoDesign1 node.
In the Properties window, set the LayoutTemplate property to ReportLayoutStyleTemplate. Also, type Customer list for the Title property.
In Model Editor, expand the AutoDesign1 node, and then select the CustomersTable node for the table data region.
In the Properties window, set the Style Template property to TableStyleTemplate.
Adding Parameters to a Report
Next, you will add parameters to the report. First, you will add a parameter and a filter that uses the parameter to allow users to select a customer for which to display data. Then, you will add parameters that will be used to determine whether to display the phone and fax numbers for the customers in the report. The following procedures explain how to define the parameters for the report.
To add a parameter and filter for selecting customers
In Model Editor, right-click the Parameters node for the report, point to Add, and then click Parameter.
Select the node for the parameter.
In the Properties window, specify the following values.
Property
Value
Multi Value
False
Name
CustomerName
Prompt String
Customers:
Values
Click the ellipsis button (...). In the dialog box that displays, click the From dataset radio button. Select Customers from the drop-down for Dataset. Select name from the drop-down menu for Value field, and select name from the drop-down menu for Label Field. Click OK.
Expand the AutoDesign1 node, and then expand the CustomersTable node.
Right-click the Filters node, and then click Add Filter.
Select the node for the filter. The filter is going to restrict the data for the report to the records from the Customers dataset where the value from the name() method matches the name supplied for the CustomerName parameter.
In the Properties window, specify the following values.
Property
Value
Expression
In the drop-down, select =Fields!name.Value.
The Expression is indicating what value is coming from the dataset.
Name
SelectCustomers
Operator
In
Value
=Parameters!CustomerName.Value
Value is the value that the user is supplying through the parameter.
To preview the report, right-click the AutoDesign1 node in Model Editor, and then click Preview. The parameter that you defined displays in the Parameters tab.
To use the parameter, select a customer name from the list that displays for the parameter, and then click the Report tab. The data for the selected customer displays.
Close the Preview window
To add parameters that determine whether to display phone and fax numbers
In Model Editor, right-click the Parameters node, point to Add, and then click Parameter.
Select the node for the parameter.
In the Properties window, specify the following values.
Property
Value
Data Type
Boolean
Name
DisplayPhoneNumber
Prompt String
Display phone number?
Values
Click the ellipsis button (...).
In the dialog box that displays, click the Non-queried radio button.
In the first row in the table, type True in the Value column and type Yes in the Label column.
In the second row, type False in the Value column and type No in the Label column.
Click OK.
In Model Editor, right-click the Parameters node, point to Add, and then click Parameter.
Select the node for the parameter.
In the Properties window, specify the following values.
Property
Value
Data Type
Boolean
Name
DisplayTeleFaxNumber
Prompt String
Display fax number?
Values
Click the ellipsis button (...). In the dialog box that displays, click the Non-queried radio button. In the first row in the table, type True in the Value column and type Yes in the Label column. In the second row, type False in the Value column and type No in the Label column. Click OK.
In Model Editor, expand the AutoDesign1 > CustomersTable > Data node.
Select the phone field, and type the expression =IIf(Parameters!DisplayPhoneNumber.Value=True, True, False) for the Visible property in the Properties window.
Select the telefax field, and type the expression =IIf(Parameters!DisplayTeleFaxNumber.Value=True, True, False) for the Visible property in the Properties window.
To preview the report, right-click the AutoDesign1 node in Model Editor, and then click Preview. The new parameters display in the Parameters window along with the previous parameter. To use the parameters, select a customer and specify Yes or No for the two display parameters. The data for the selected customers displays.
Close the Preview window.
See also
How to: Define a Report Parameter