Share via


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

  1. Open the Microsoft Dynamics AX development workspace.

  2. In the AOT, right-click the Queries node, and then click New Query.

  3. Right-click the node for the query, click Rename, and then type CustomerList.

  4. Expand the node for the CustomerList query.

  5. In the AOT, right-click the Data Dictionary node, and then click Open New Window.

  6. In the new window, expand the Tables node.

  7. Locate the CustTable table and drag it onto the Data Sources node for the CustomerList query.

  8. Expand the CustomerList > Data Sources > CustTable_1 and then click Fields. In the Properties window, set the Dynamic property to Yes.

  9. 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

  1. Open Microsoft Visual Studio.

  2. On the File menu, point to New, and then click Project. The New Project dialog box displays.

  3. In the Installed Templates pane, click the Microsoft Dynamics AX node, and in the Templates pane, click Report Model.

  4. In the Name box, type SampleCustomerListReport, and in the Location box, type a location.

  5. 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

  1. In Solution Editor, right-click the SampleCustomerListReport project, point to Add, and then click Report.

  2. In Model Editor, edit the Name property for the report and type CustomerList.

  3. Right-click the Datasets node, and then click Add Dataset.

  4. Select the node for the dataset.

  5. 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

    1. 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.

    2. Select the CustomerList query and then click Next.

    3. In the Select Fields tab, expand the All Fields node and then select the AccountNum field.

    4. Expand the All Display Methods node and select the address, name, phone and telefax methods.

    5. Click OK.

  6. In Model Editor, select the Customers node and drag it onto the Designs node. An auto design named AutoDesign1 is created for the report.

  7. Select the AutoDesign1 node.

  8. In the Properties window, set the LayoutTemplate property to ReportLayoutStyleTemplate. Also, type Customer list for the Title property.

  9. In Model Editor, expand the AutoDesign1 node, and then select the CustomersTable node for the table data region.

  10. 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

  1. In Model Editor, right-click the Parameters node for the report, point to Add, and then click Parameter.

  2. Select the node for the parameter.

  3. 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.

  4. Expand the AutoDesign1 node, and then expand the CustomersTable node.

  5. Right-click the Filters node, and then click Add Filter.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. Close the Preview window

To add parameters that determine whether to display phone and fax numbers

  1. In Model Editor, right-click the Parameters node, point to Add, and then click Parameter.

  2. Select the node for the parameter.

  3. In the Properties window, specify the following values.

    Property

    Value

    Data Type

    Boolean

    Name

    DisplayPhoneNumber

    Prompt String

    Display phone number?

    Values

    1. Click the ellipsis button (...).

    2. In the dialog box that displays, click the Non-queried radio button.

    3. In the first row in the table, type True in the Value column and type Yes in the Label column.

    4. In the second row, type False in the Value column and type No in the Label column.

    5. Click OK.

  4. In Model Editor, right-click the Parameters node, point to Add, and then click Parameter.

  5. Select the node for the parameter.

  6. 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.

  7. In Model Editor, expand the AutoDesign1 > CustomersTable > Data node.

  8. Select the phone field, and type the expression =IIf(Parameters!DisplayPhoneNumber.Value=True, True, False) for the Visible property in the Properties window.

  9. Select the telefax field, and type the expression =IIf(Parameters!DisplayTeleFaxNumber.Value=True, True, False) for the Visible property in the Properties window.

  10. 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.

  11. Close the Preview window.

See also

How to: Define a Report Parameter

How to: Define a Report Filter

Controls Used to Render Report Parameters