Вы находитесь на странице: 1из 60

Chapter 12: Reporting

CHAPTER 12: REPORTING


Objectives
The objectives are: Explain the report capabilities in Microsoft Dynamics AX 2012. Describe the key concepts involved when specifying data for your reports. Create a new query and then bind the query to a new SQL Server Reporting Services report together with an auto design. Add sorting, grouping, filters, and parameters to a report. Save, deploy, and view a report in Microsoft Dynamics AX. Discuss the Model-View-Controller (MVC) pattern. Define the report dataset. Create a temporary table to store the report dataset. Manage report parameters in a data contract class in X++. Create a report data provider (RDP) class. Work with report precision design. Explain how to print a report, set the print settings, prevent the display of print setup, set the query range, and set a report parameter value in X++. Review how reports bound to a report data method can contain business logic to access data. Describe the components of print management and the steps that are used to implement each component of print management.

Introduction
SQL Server Reporting Services (SSRS) is the primary reporting platform for Microsoft Dynamics AX 2012. The default, out-of-the-box reports that are provided with Microsoft Dynamics AX run on the Reporting Services platform. They give users better looking reports, more export formats, and a more capable report designer. The goals for this transition include following: Use the Microsoft technology stack. Keep business logic in Microsoft Dynamics AX. Transition for X++ and C# developers to the new reporting architecture is simplified.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-1

Development IV in Microsoft Dynamics AX 2012


This chapter introduces you to the features of SSRS and shows how to create simple reports by using a query and an auto-design. In addition, a complex report using by the new report data provider framework in a precision design is reviewed. The model-view-controller coding pattern for report data providers is discussed and tips for selecting the correct development technology for your reports are reviewed.

Reporting Features Overview


The following topics review the features and capabilities of SSRS in Microsoft Dynamics AX 2012.

Reporting Architecture
The report development pattern in used for SSRS reports Microsoft Dynamics AX 2012 uses the Model-View-Controller (MVC) design pattern variation. This pattern allows many client types to call Microsoft Dynamics AX 2012 Reporting Services reports including: Microsoft Dynamics AX clients, Enterprise Portal, and Batch Job. This also means that Reporting Services can be replaced by a different application for rendering reports. The following figure illustrates the SSRS architecture in Microsoft Dynamics AX 2012.

FIGURE 12.1 SSRS REPORTING ARCHITECTURE

12-2

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Installation and Deployment
When you installed the components in Microsoft Dynamics AX 2009, you had to install the reporting extensions while running the Setup wizard. For Microsoft Dynamics AX 2012, the Setup wizard is changed. It no longer includes an option for installing the reporting extensions. When you run the Setup wizard for Microsoft Dynamics AX 2012, you can install the business intelligence components. While installing the business intelligence components, the Setup wizard will: Verify that prerequisite software is installed on the server. Prompt you to select a SQL Server Reporting Services instance. Prompt you to select a SQL Server Analysis Services instance.

Reports in Microsoft Dynamics AX 2012 are deployed by using PowerShell scripts.

Upgrade Consideration
Reports and cubes are not upgraded to Microsoft Dynamics AX 2012. The X++ reporting framework is being deprecated in Microsoft Dynamics AX 2012. Reports that are based on the X++ reporting framework and existing SQL Server Reporting Services reports will be copied to the Microsoft Dynamics AX 2012 system. However, they will not be upgraded. It is recommended to use a SQL Server Reporting Services report that is provided with Microsoft Dynamics AX 2012 as a template and customize it to meet your needs.

Configuration
You can use the Reporting services framework to modify the queries used to retrieve data for reports. This means that you can now use SQL Reporting Services capabilities to filter, group, and sort data in reports.

Auto-Reports
With Microsoft Dynamics AX 2012, you can use the Auto-report wizard to create custom, ad hoc reports that are based on the SQL Server Reporting Services framework. To start the Auto-report wizard, click the Print icon on a form.

Batch Support
SQL Server Reporting Services reports in Microsoft Dynamics AX 2012 are now integrated with the Microsoft Dynamics AX batch framework. You can schedule a long-running report to print during off-peak hours and schedule a report to print on a recurring basis.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-3

Development IV in Microsoft Dynamics AX 2012


Report Web Parts
The Web Part used to display reports in Role Centers and other Enterprise Portal pages is updated. This Web Part used for adding an SSRS report is called Microsoft Dynamics AX Report. The Web Part has also been updated to improve usability. Now it is easier to add the Web Part to a page, select a report to display in the Web Part, and select parameters to filter the data displayed on the report.

Support for Multiple Languages


In Microsoft Dynamics AX 2012, you can deploy a report that will automatically reflect all supported languages when labels are used for the static text.

Report Data Overview


You can use the Microsoft Visual Studio tools for Microsoft Dynamics AX to create reports by using data from several different sources. This topic provides a description of the key concepts involved when specifying data for your reports.

Report Data Sources


A data source represents a source of data for one or more reports. Depending on where the data is located, you can use the data source for Microsoft Dynamics AX, or you can define your own data source.

Dynamics AX Data Source


The Dynamics AX data source is provided for you. It connects to the Microsoft Dynamics AX database. With this data source, you can use queries and Report Data Provider classes that are defined within the Application Object Tree (AOT) in Microsoft Dynamics AX, and data methods that are defined within your reporting project in Visual Studio. The Microsoft Dynamics AX data source does not display in the model with the other report elements. It is available from the drop-down menus in the reporting tools, and it can be used for a system that works from a SQL database with no additional modifications needed for reports. When you select Microsoft Dynamics AX as the data source for the report, you will point to the active Application Object Server (AOS). If you want to use an AOS from another computer that is not the active AOS, you must configure the Business Connector session by using the client configuration utility to point to another AOS.

Defining Additional Data Sources


You can define additional data sources as needed. For example, you can create a data source to connect to data from a legacy system, online analytical processing (OLAP) data, or some other external database.

12-4

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


NOTE: You can use the Dynamics AX OLAP data source type to connect to databases deployed by using the Cube Administration wizard. You define a data source in a model with the other report elements, and you must also specify a data provider and a connection string. The data provider serves as a bridge between a report and its data and is used to retrieve the data. There are two providers that you can choose from when defining a data source: SQL and OLAP. The connection string that you supply contains the information that is used when connecting to the data source. For example, if you are connecting to an SQL database, you can specify the server name, the database name, and the authentication method for validating a user. After you have defined a data source, it is displayed as an element in your model and is available as an option in drop-down menus in the reporting tools. A data source can be shared by one or more reports. A report can use one or more data sources.

Report Datasets
A report dataset identifies the data from a data source that displays in a report. When you define a dataset, you must specify the data source and the means used to retrieve the data, such as a query or data method. The following table describes the options for retrieving data for a report. Data source Dynamics AX Option Queries that are defined in the AOT SQL OLAP Report Data Provider classes that are defined in the AOT Data methods that are defined within a reporting project in Microsoft Visual Studio TSQL query Stored procedure Dynamics AX OLAP

MDX query, this is used to connect to third party databases.

If your report uses the Dynamics AX data source and a query that is defined in the AOT in Microsoft Dynamics AX, you must be especially careful when updating the query in the AOT. For example, if you remove a field in the query and the field displays in the report, the report will display an empty column for the field. Whenever you make updates to a query, consider how those updates can affect your reports. Updates to a query can also require updates to your reports. A report can have multiple datasets. A dataset can be used by one or more data regions in a report.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-5

Development IV in Microsoft Dynamics AX 2012


Security Considerations
When accessing data from the Microsoft Dynamics AX database, it is recommended that you use the Microsoft Dynamics AX data source to make sure that appropriate security is enforced. When you use the Microsoft Dynamics AX data source, you can use queries or Report Data Provider classes that are defined in the AOT. All data access requests are processed by using the MorphX security system. When you use an external SQL or OLAP data source, security from the MorphX security system is not applied when accessing data. In this case, you can use the role-based security features that are available from Microsoft SQL Server to help secure the data.

Guidance for Choosing Data Source Types


When you define a report in Microsoft Dynamics AX you must specify how to access the data for your report. The options for a data source type are query, business logic, and report data provider. The following table provides detail on when to use each data source type to access data for your report. Data Source Type Query Description Use when data can be accessed by using an AX Query. An AX Query is a query that is defined in the AOT. No X++ code is involved except for display methods. A query to access data has the following advantages: A query with a display method has no code that needs to run. You can query for data directly from a table. Filtering occurs in SQL which is faster. Business Logic There are no X++ classes to develop. You define a query in the AOT.

Use when your business logic is contained in C# code. Your code must return a dataset.

12-6

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Data Source Type Report Data Provider Description Use when portions of the report data set are derived from business logic contained in X++ code. The following lists specific examples. Business logic processing is based on parameters values. Data to be rendered can be materialized by calling X++ business classes. Use dynamic filters to allow the user to add more filters to an underlying query at run time.

NOTE: A query should be considered before you use a Report Data Provider class. AX Enum Provider Use when the report parameter is an Enum type. These parameters expose Enum types on a report in a friendly drop-down list. You can create a range on a query to expose an enum parameter in the Microsoft Dynamics AX client. However, if you want the report to be run from the Enterprise Portal, you must use an AX Enum Provider to define the parameter.

A controller class runs the report by creating the UI, calling SQL Server Reporting Services, and preprocessing the parameters for the report. If any of the following scenarios occur, you must extend the SrsReportRunController class to create a custom controller for the report. Report requires input data to be preprocessed. Report requires input data to be manipulated or modified. Multiple reports should be run from the same dialog box.

NOTE: Reports that use a controller class must take care of the parameters when the report is used on the Enterprise Portal.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-7

Development IV in Microsoft Dynamics AX 2012

Creating Basic Reports from a Query


This lesson focuses on the basics for developing simple reports. There are several ways to retrieve data for reports. In this walkthrough, you will use a query that is defined in the AOT within the Microsoft Dynamics AX development environment. The following illustration shows the report that you will create.

FIGURE 12.2 SAMPLE CUSTOMER TRANSACTION LIST REPORT

Development Actions
The following demonstration shows how to create a query bound report that exposes Customer Transaction data. The steps that are involved include create a Microsoft Dynamics AX query, add field data to the query, create a new report model in Visual Studio, create a report dataset, create a report design and apply style templates.

Demonstration: Define a Query


To create a new query in the AOT, follow these steps: 1. Open the 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 a name such as CustTrans_W1. 4. Expand the CustTrans_W1 node. 5. Right-click the Data Dictionary node, and then click Open New Window. 6. In the new window, expand the Tables node. 7. Locate the CustTrans table and drag it onto the Data Sources node for the CustTrans_W1 query.

12-8

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Demonstration: Add Table Field Data to a Query
To select fields on the query, follow these steps: 1. 2. 3. 4. Locate the CustTrans_W1 query. Expand the CustTrans_1 dataset node. Right-click the fields node of the query, click Properties. Set the Dynamic property to Yes, and then save the report. Then set the property to No so fields can be removed from the view. 5. Only include the following fields in your dataset view "AccountNum", "AmountCur", "Invoice", "TransDate", "TransType", and "Txt". You can delete fields by highlighting the desired fields and then right-click and select Delete, then click OK to accept the deletion. 6. Save the query.

Demonstration: Create a New Report in Visual Studio


To create a new reporting project and report, follow these steps: 1. Open Microsoft Visual Studio 2010. 2. On the File menu, point to New, and then click Project. The New Project dialog box is displayed. 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 a name for the project such as CustTrans_W1, and in the Location box, type a file path to save the project. 5. Click OK. 6. If the Solution Explorer pane is not open click View > Solution explorer. 7. In the Solution Explorer pane, click the Add button and select Report. An empty report model named Report1 is created.

Demonstration: Create a Report Dataset


The dataset in a report is similar to the data sources of a form. They are used to define the data that will be selected and displayed on a report. To create a query based dataset, follow these steps: 1. In the Model Editor, right-click the Report1 node, and then click Rename. 2. Type CustTrans_W1 as the name. 3. Expand the CustTrans_W1 node if it is not already expanded. 4. Right-click the Datasets node, and then click Add Dataset. 5. Select the node for the dataset.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-9

Development IV in Microsoft Dynamics AX 2012


6. In the Properties window, specify the following values. a. Data Source = Dynamics AX b. Data Source Type = Query c. Default Layout = Table d. Name = CustTransDS e. Query = Select * from CustTrans_W1

Demonstration: Create a Report Design


To view the report data by using an AutoDesign, follow these steps: 1. In the Model Editor, select the CustTransDS node and drag it onto the Designs node. An auto design named AutoDesign1 is created for the report. 2. Right-click the AutoDesign1 node, and then click Preview. The Error List pane will open with warnings. This can be ignored. 3. Click the Report tab on the Preview window to view the report. The report appears unformatted, because you have not yet applied any layout or style templates to it. The following figure is a sample of how the report will look.

FIGURE 12.3 REPORT PREVIEW SAMPLE

4. Close the Preview window.

12-10

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Demonstration: Apply Layout Templates
The Error List window shows two warnings about the layout template and the table style template. This warnings must be corrected to change the formatting of the report to appear more like a standard report. To apply layout and style templates, follow these steps. 1. In the Model Editor, select the AutoDesign1 node. 2. In the Properties window, set the LayoutTemplate property to ReportLayoutStyleTemplate. 3. Type "Customer Transaction List" for the Title property. 4. In the Model Editor, expand the AutoDesign1 node, and then select the node for the CustTransDSTable data region. 5. In the Properties window, set the Style Template property to TableStyleTemplate. 6. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. 7. When the Preview window opens, click the Report tab. The following figure is a sample of how the report will look.

FIGURE 12.4 REPORT PREVIEW SAMPLE

8. Close the Preview window.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-11

Development IV in Microsoft Dynamics AX 2012


Demonstration: Add Column Sorting to the Report
The following demonstration shows how to add column sorting to an AutoDesign report by using built in tools. The two steps that are involved include establishing default sorting, and enabling run-time column sorting.

Procedure: Add Default Sorting to the Report


To establish default sorting based on a dataset column follow these steps: 1. In the Model Editor, expand the AutoDesign1 node, and then select the Sorting node under the CustTransDSTable data region. 2. Right-click the Sorting node, and then click Add Sort. 3. Type AccountNum as the name. 4. In the Properties window, set the Sort By property to =Fields!AccountNum.Value. 5. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new sorting for the report. 6. When the Preview window opens, click the Report tab. 7. Close the Preview window. 8. Save the report.

Procedure: Enable Run-Time Sorting


To modify the column properties so that the user can decide the column sorting, follow these steps. 1. In the Model Editor, expand the AutoDesign1 node, and then select the AccountNum field under the Data region of the CustTransDSTable node. 2. In the Properties window, set the Interactive sorting property to True. 3. Repeat step 1 and 2 for the AmountCur, TransDate, and TransType1 columns. 4. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report.

12-12

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


5. When the Preview window opens, click the Report tab. The following figure is a sample of how the report will look when sorted by the date. Notice the sorting arrows next to the Customer account, Amount transaction in currency, and Date fields.

FIGURE 12.5 REPORT PREVIEW SAMPLE

6. Close the Preview window. 7. Save the report.

Demonstration: Grouping Report Data


The following procedures show how to group report data by using Visual Studio Tooling. The two steps that are involved include group report data based on customer account and then aggregate group data to display totals.

Procedure: Group the Report Data


To group the report dataset, follow these steps: 1. In the Model Editor, expand the AutoDesign1 node. 2. Right-click the Groupings node under the CustTransDSTable data region, and then click Add Grouping. 3. Type Group1 as the name. 4. In the Properties window, set the Label property to =Fields!AccountNum.Value. 5. Right-click the Group on node, and then click Add Group on. 6. Type AccountNum as the name.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-13

Development IV in Microsoft Dynamics AX 2012


7. In the Properties window, set the Expression property to =Fields!AccountNum.Value. 8. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. 9. When the Preview window opens, click the Report tab. The following figure is a sample of how the report will look when grouped by the account number.

FIGURE 12.6 REPORT PREVIEW SAMPLE

10. Close the Preview window. 11. Save the report.

Procedure: Aggregate Grouped Data


To aggregate report data in the footer, follow these steps: 1. In the Model Editor, expand the AutoDesign1 node, and then select the AccountNum field under the Data node. 2. Right-click the Group1 node, and then click Properties. 3. In the Properties window, expand Instance Aggregates, and set Render Location to Group Footer. 4. Select the AmountCur field under the Data node 5. In the Properties window, expand the Aggregation item, and set Aggregate Function to Sum. 6. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. 7. When the Preview window opens, click the Report tab. Notice the totals for each customer.

12-14

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


8. Close the Preview window. 9. Save the report.

Demonstration: Add Filtering to a Report


The following procedure shows how to filter report data based on user input by using a free text control. The steps that are involved include adding a range to the Microsoft Dynamics AX query, adding a parameter to the report, and filtering the data by using the parameter value supplied.

Procedure: Add a Range to the Query


To add a query range, follow these steps: 1. Open Microsoft Dynamics AX. 2. Open the Development Workspace. 3. In the AOT, right-click the Queries node, and then locate the CustTrans_W1 query. 4. Browse to Data Sources > CustTrans_1 > Ranges node. 5. Right-click the Ranges node, and then click New Range. A default range by using the AccountNum field is created for you by Microsoft Dynamics AX. 6. Save the query.

Procedure: Add a Parameter to the Report


To add a report parameter, follow these steps. 1. Open the report in Visual Studio. 2. In the Model Editor, select the CustTransDS node. 3. Right-click the node and select Refresh to reflect changes that were made to the Microsoft Dynamics AX query 4. Expand the Parameters node of the report (make sure not to select the Parameters node of the dataset) to display the list of report parameters. 5. Right-click the node and select Add > Parameter 6. Type AccountParam as the name 7. In the Properties window, set the Prompt String property to Account. 8. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new parameter for the report. Notice the new Account field on the Parameters tab. 9. Close the Preview window. 10. Save the report.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-15

Development IV in Microsoft Dynamics AX 2012


Procedure: Filter Data by Using the Parameter Value
At this point the report has a parameter added. However, the data on the report is not being filtered when a value is entered into the parameter field. To filter the report dataset, follow these steps. 1. 2. 3. 4. 5. 6. 7. 8. In the Model Editor, expand the AutoDesign1 node. Right-click the Filters node and select Add Filter. Type AccountFilter as the name. In the Properties window, set the Expression property to =Fields!AccountNum.Value. Set the Operator property to Like. Set the Value property to =Parameters!AccountParam.Value In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new settings for the report. On the Parameters tab, enter 1101 into the Account field, and then click the Report tab. The following figure is a sample of how the report will look when filtered for account number 1101.

FIGURE 12.7 SAMPLE REPORT PREVIEW

9. Close the Preview window. 10. Save the report.

Demonstration: Add Dynamic Parameters to the Report


The last example showed how to add a parameter to the report that allows users to enter a free form string. However, in a more realistic example, report parameters often times have a predefined list of values. For example, there is a predefined list of customer account numbers. Instead of allowing the user to type in any value, which might not be valid, you can change the parameter to include a drop-down list of valid values.

12-16

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


The following demonstration shows how to filter report data based on a dynamic parameter that is bound to a Microsoft Dynamics AX query. The steps that are involved include creating a Microsoft Dynamics AX query, creating a new dataset and binding it to the query, binding the report parameter to the query results, and filtering the report dataset by using the parameter value.

Procedure: Define a Query


To define a query, follow these steps: Open Microsoft Dynamics AX. Open the Development Workspace. Create a new query. Rename the query to CustTable_W1. Expand the CustTable_W1 node. Locate the CustTable table and drag it onto the Data Sources node for the CustTable_W1 query. 7. Select the CustTable_1 data source, and then highlight the Fields node and set the Dynamic property to No. 8. Right-click the Fields node and select New > Field. 9. Save the query. 1. 2. 3. 4. 5. 6.

Procedure: Bind a Dataset to the Query


To bind a dataset to the Query, follow these steps: 1. Open the report that you created earlier in Visual Studio. 2. In the Model Editor, right-click the Datasets node, and then click Add Dataset. 3. Type CustomersDS as the name. 4. Select the node for the dataset. 5. In the Properties window, specify the following values: a. Data Source = Dynamics AX b. Data Source Type = Query c. Default Layout = Table d. Name = CustomerDS e. Query = Select * from CustTable_W1

Procedure: Bind Report Parameters to a Data Source


To bind report parameter to a dataset, follow these steps. 1. In the Model Editor, select the AutoDesign1 node. 2. Expand the Parameters node to display the list of report parameters 3. Select the AccountParam node.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-17

Development IV in Microsoft Dynamics AX 2012


4. In the Properties window, click the elipses (...) button in the Values property. 5. Select the From Dataset option and set the following: a. Dataset: CustomersDS b. Value Field: AccountNum c. Label Field: AccountNum 6. Click OK. 7. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new settings for the report. Notice the Account field on the Parameters tab now shows a list of all customers and a check box next to each customer number which allows you to select multiple customers. 8. Close the Preview window. 9. Save the report.

Demonstration: Save and Deploy the Report


At this point you have only viewed the report from inside Visual Studio. In order for users to be able to use the new report that you have created, you must save and deploy the report. To save the report to the AOT and deploy to the SSRS Server, follow these steps. 1. Rebuild the solution a. Right-click the project (CustTrans_W1) in the Solution Explorer pane, and select Rebuild. b. Verify that you have no build errors. 2. Save the report to the AOT a. Right-click the project (CustTrans_W1) in the Solution Explorer pane, and select Add CustTrans_W1 to AOT. b. Verify that you can add to the AOT. 3. Deploy the Report a. Right-click the project (CustTrans_W1) in the Solution Explorer pane, and select Deploy. b. Verify that you can deploy the report.

12-18

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Demonstration: View the Report in Microsoft Dynamics AX
The following demonstration shows how to view the report in the Microsoft Dynamics AX client. The steps that are involved include creating a Microsoft Dynamics AX menu item linked to the newly created report design, viewing the report in the Microsoft Dynamics AX client, and adding the menu item to the menu.

Procedure: Create a Menu Item


To create a menu item in Microsoft Dynamics AX, follow these steps. 1. Open the Development Workspace. 2. In the AOT window, expand the Menu Items node and select the Output node. 3. Right-click the Output node and then click New Menu Item. 4. Type CustTrans_W1 as the name. 5. Right-click the CustTrans_W1, select Properties, and then set the following a. ObjectType: SSRSReport b. Object: CustTrans_W1 c. ReportDesign: AutoDesign1 d. Label: Customer transaction list 6. Save the menu item. 7. Right-click the CustTrans_W1 menu item and select Open.

FIGURE 12.8 CUSTOMER TRANSANCTION LIST REPORT DIALOG BOX

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-19

Development IV in Microsoft Dynamics AX 2012


Procedure: Add a Menu Item to the Menu
To add a menu item to the menu, follow these steps: Open Microsoft Dynamics AX. Open the Development Workspace. In the AOT, expand Menu Items node and select the Output node. Right click the Output node, and then select Open New Window. In the original AOT window, expand Menus. Expand AccountsReceivable > Reports > Transactions > Customer. 7. Select the Menu Item to add to the menu in the new AOT window that was opened in step 4. 8. Drag the Menu Item into the Menu. IMPORTANT: You cannot view the changes to the menu unless you log off Microsoft Dynamics AX and then log on again. BEST PRACTICE: It is recommended that all menu items have security implemented. For more information about how to develop security permissions and privileges, refer to the Help. TIP: You can import the AX2012_ENUS_DEVIV_12_01_DEMO.xpo file which contains the sample customer transaction list report created in this demonstration. 1. 2. 3. 4. 5. 6.

12-20

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting

Lab 12.1 - Report Workshop


This lab demonstrates creating a report from a query. The report design includes sorting, grouping, filtering, and parameters. Scenario Isaac, the Developer, wants to create a Reporting Services report to expose vendor transaction data.

Challenge Yourself!
Use the information that is provided to create a query bound report that exposes vendor transaction data. Create the new report in Visual Studio and add sorting and grouping by vendor account to the report. Then add a report filter for the account number, and add a dynamic parameter for the vendor account. When you are finished, save and deploy the report and add a menu item to the Accounts Payable module to view the report on the menu.

Need a Little Help?


Create a Microsoft Dynamics AX query for the VendTrans table. Add field data to the query. Create a new report model in Visual Studio. Create a report dataset. Create a report design. Apply Style Templates. Add sorting and grouping for the account number. Filter report data by account number. Create a dynamic parameter for the account number. Save and deploy the report. Create a menu item. Add the menu item to the Accounts Payable > Reports > Transactions > Vendor menu. 13. View the report in Microsoft Dynamics AX 2012. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.

Step by Step: Create a Query


1. Open Microsoft Dynamics AX. 2. Open the Development Workspace. 3. In the AOT, right-click the Queries node, and then click New Query. 4. Right-click the node for the query, click Rename, and then type VendTrans_W1. 5. Expand the VendTrans_W1 node.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-21

Development IV in Microsoft Dynamics AX 2012


6. Right-click the Data Sources node and then select New Data Source. 7. Enter VendTrans into the Table property field. 8. Expand the VendTrans_1 Dataset node. 9. Right-click the Fields node of the query, click Properties. 10. Change the Dynamic property to No so that fields can be removed from the view. 11. Only include the following fields in your dataset view AccountNum, AmountCur, TransDate, TransType, and Txt. 12. Save the query.

Step by Step: Create a New Report in Visual Studio


1. Open Microsoft Visual Studio 2010. 2. On the File menu, point to New, and then click Project. The New Project dialog box appears. 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 SSRSDemo, and in the Location box, type a file path. 5. Click OK. 6. In the Solution Explorer, click the Add button and select Report. An empty report model named Report1 is created. 7. In the Model Editor, right-click the Report1 node, and then click Rename. 8. Type VendTrans_W1 as the name. 9. Expand the VendTrans_W1 node if it is not already expanded. 10. Right-click the Datasets node and then click Add Dataset. 11. Select the node for the dataset. 12. In the Properties window, specify the following values: 13. Set the Data Source property to Dynamics AX. 14. Set the Data Source Type property to Query. 15. Set the Name property to VendTransDS. 16. Set the Query property to Select * from VendTrans_W1. 17. In the Model Editor, select the VendTransDS node and drag it onto the Designs node. An auto design named AutoDesign1 is created for the report. 18. Optional: Right-click the AutoDesign1 node, and then click Preview and select the Report tab. The report appears unformatted, because you have not yet applied any layout or style templates to it. Close the Preview window.

12-22

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Step by Step: Apply Layout Template
1. In the Model Editor, select the AutoDesign1 node. 2. In the Properties window, set the Layout Template property to ReportLayoutStyleTemplate. Also, type Vendor Transaction List for the Title property. 3. In the Model Editor, expand the AutoDesign1 node, and then select the node for the VendTransDSTable data region. 4. In the Properties window, set the Style Template property to TableStyleTemplate. 5. Optional: In the Model Editor, right-click the AutoDesign1 node, and then click Preview and select the Report tab to view the new style settings for the report. Close the Preview window.

Step by Step: Add Column Sorting


1. In the Model Editor, expand the AutoDesign1 node, and then select the Sorting node under the VendTransDSTable data region. 2. Right-click the Sorting node and then click Add Sort. 3. Type AccountNum as the name. 4. In the Properties window, set the Sort By property to =Fields!AccountNum.Value. 5. In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. 6. Close the Preview window. 7. Save the report. 8. In the Model Editor, expand the AutoDesign1 node, and then select the AccountNum field under the Data region. 9. In the Properties window, set the Interactive sorting property to True. 10. Repeat steps 8 through 9 for the AmountCur, TransDate, and TransType1 columns. 11. Optional: In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. Close the Preview window. 12. Save the report.

Step by Step: Grouping Report Data


1. In the Model Editor, expand the AutoDesign1 node. 2. Right-click the Groupings node under the VendTransDSTable data region, and then click Add Grouping. 3. Type Group1 as the name. 4. In the Properties window, set the Label property to =Fields!AccountNum.Value.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-23

Development IV in Microsoft Dynamics AX 2012


5. Right-click the Group on node, and then click Add Group on 6. Type AccountNum as the name. 7. In the Properties window, set the Expression property to =Fields!AccountNum.Value. 8. Right-click the Group1 node and then click Properties. 9. In the Properties window, expand Instance Aggregates, and set Render Location to GroupFooter. 10. Select the AmountCur field under the Data node. 11. In the Properties window, expand the Aggregation item, and set Aggregate Function to Sum. 12. Optional: In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. Close the Preview window.

Step by Step: Filtering Report Data


1. Open Microsoft Dynamics AX. 2. Open the Development Workspace. 3. In the AOT, right-click the Queries node, and then locate the VendTrans_W1 query. 4. Expand the VendTrans_W1 nodes. 5. Right-click the Ranges node and then click New Range. A default range by using the AccountNum field is created for you by Microsoft Dynamics AX. 6. Save the query. 7. In the Model Editor, select the VendTransDS node. 8. Right-click the node and select Refresh to reflect changes that were made to the Microsoft Dynamics AX query. 9. Expand the Parameters node to display the list of report parameters. 10. Right-click the node and select Add > Parameter. 11. Type AccountParam as the name. 12. In the Properties window, set the Prompt String property to Account. 13. Optional: In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. Close the Preview window. 14. Save the report. 15. In the Model Editor, expand the AutoDesign1 node. 16. Right-click the Filters node and select Add Filter. 17. Type AccountFilter as the name. 18. In the Properties window. a. Set the Expression property to =Fields!AccountNum.Value. b. Set the Operator property to Like. c. Set the Value property to =Parameters!AccountParam.Value.

12-24

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


19. Optional: In the Model Editor, right-click the AutoDesign1 node, and then click. Preview to view the new style settings for the report. Close the Preview window. 20. Save the report.

Step by Step: Add a Dynamic Parameter


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Open Microsoft Dynamics AX. Create a new query. Rename the query to VendTable_W1. Expand the VendTable_W1 node. Locate the CustTable table and drag it onto the Data Sources node for the VendTable_W1 query. Include the AccountNum field in your dataset view. Save the query. In the Model Editor, right-click the Datasets node, and then click Add Dataset. Type VendorDS as the name. Select the node for the dataset. In the Properties window, specify the following values: a. Set the Data Source property to Dynamics AX. b. Set the Data Source Type property to Query. c. Set the Default Layout property to Table. d. Set the Name property to VendorDS. e. Set the Query property to Select * from VendTable_W1. In the Model Editor, select the AutoDesign1 node. Expand the Parameters node to display the list of report parameters. Select the AccountParam node. In the Properties window, click the button in the Values property. Select the From Dataset option and set the following: a. Set the Dataset property to VendorDS. b. Set the Value Field property to AccountNum. c. Set the Label Field property to AccountNum.

12. 13. 14. 15. 16.

17. Optional: In the Model Editor, right-click the AutoDesign1 node, and then click Preview to view the new style settings for the report. 18. Optional: Close the Preview window. 19. Save the report.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-25

Development IV in Microsoft Dynamics AX 2012


Step by Step: Save and Deploy the Report
1. Right-click the SSRSDemo project in the Solution Explorer, and select Rebuild. 2. Verify that you have no build errors. 3. Right-click the SSRSDemo project in the Solution Explorer, and select Add SSRSDemo to AOT. 4. Verify that you can add to the AOT. 5. Right-click the SSRSDemo project in the Solution Explorer, and select Deploy. 6. Verify that you can add to the AOT.

Step by Step: View the Report in Microsoft Dynamics AX


1. 2. 3. 4. 5. 6. Open Microsoft Dynamics AX. Open the Development Workspace. In the AOT, expand Menu Items node and select the Output node. Right-click the Output node and then click New Menu Item. Type VendTrans_W1 as the name. Right-click the VendTrans_W1 and select Properties to set the following: a. Set the ObjectType property to SSRSReport. b. Set the Object property to VendTrans_W1. c. Set the Label Field property to AutoDesign1.

Save the Microsoft Dynamics AX Menu Item. Right-click the VendTransList_WS1 menu item and select Open. In the AOT, expand Menu Items node and select the Output node. Right click the Output node, and then select Open New Window. In the original AOT window, expand Menus. Expand AccountsPayable > Reports > Transactions > Vendor. Select the VendTrans_W1 Menu Item in the new AOT window that was opened in step 4. 14. Drag the Menu Item into the Menu. 15. Save the Menu.

7. 8. 9. 10. 11. 12. 13.

12-26

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting

Create a Precision Design Report from a Report Data Provider


Basic views of Microsoft Dynamics AX data can most frequently be accomplished by using queries to retrieve and structure the report dataset. Reports that illustrate more complex data analysis will most likely include custom business logic to produce the desired output. This lesson discusses the concepts in Microsoft Dynamics AX 2012 that developers can use to take advantage X++ code to construct the report dataset.

Model-View-Controller
Model-view-controller (MVC) is a pattern used to isolate business logic from the user interface. By using MVC, the model represents the information (the data) of the application and the business rules used to manipulate the data, the view corresponds to elements of the user interface such as text, checkbox items, and so on, and the controller manages details involving the communication between the model and view. The controller handles user actions such as keystrokes and mouse movements and pipes them into the model or view as required. Model: Responsible for retrieving data and for business logic, this can included queries, data methods, or other classes that are designed to retrieve data. View: Responsible for the User Interface, this can also be thought of as the design for the report. Controller: Orchestrates the flow between Model and View

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-27

Development IV in Microsoft Dynamics AX 2012


The following figure illustrates an example of how the model-view-controller can be used in an advanced report.

FIGURE 12.9 MODEL-VIEW-CONTROLLER

The Creating Basic Reports from a Query topic reviewed a simple example of a report where all of these elements existed. However, the design and the control of the report were not modified. Instead the base classes for the SSRS reporting framework in Microsoft Dynamics AX 2012 rendered the report dialog and handled the logic that was required to run the report. The steps used to create a report data provider that will deliver data to a report follow.

Define the Report Dataset


Tables are used to store the report dataset generated by the X++ data access class. BEST PRACTICE: A temporary table is typically used for report data providers. It is recommended to use DBTemp tables when the data set being returned contains more than 1,000 records. The steps that are involved include review and define the data structure for the report, create a temporary table to store the report dataset, and add table fields required to generate the report.

12-28

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


To review and define the data structure for the report dataset, follow these steps. 1. Take an inventory of the data that is used to make up your report. 2. Identify the elements of the report that are derived from the report business logic. 3. Identify calculated columns that are based on Microsoft Dynamics AX data. 4. Determine the extended data types that are used to format the data. The following figure is a sample of a completed report that will be built during the following demonstrations.

FIGURE 12.10 REPORT DEMONSTRATION SAMPLE

TIP: Before you begin development for a new report visualize the layout of the report using by Microsoft Office Excel or draw the report design on a piece of paper.

Demonstration: Create a Temporary Table


To create a temporary table, follow these steps. 1. 2. 3. 4. 5. Open Microsoft Dynamics AX. Open the Development Workspace. In the AOT, right-click the Tables node and then click New Table. Right-click the table node, click Properties. Locate the Name property and then type a AOTObjectsTmp.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-29

Development IV in Microsoft Dynamics AX 2012


6. Locate the TableType property and then select InMemory. 7. Save the table. To add a field to the table, follow these steps: 1. Expand the Fields node. 2. Right-click the fields node of the table and then click New > String. 3. Create a new field and name it Node and set the ExtendedDataType property to Description. 4. Add a label for the field node. 5. Repeat steps 1 through 4 for two additional fields, for the ParentNode and the Property. Make sure that you select the extended data type that you want for each field when you click New. 6. Save the table. NOTE: Some reports can require more than one temporary table to store the information.

Manage Report Parameters


A data contract is an abstract description of a set of fields that have a name and data type for each field. The data contract exists outside any single implementation so that services on different platforms can interoperate. As long as the data passed between the services complies with the same contract, all the services can process the data. Report parameters that are used by custom business logic are managed by a data contract class in X++. The steps that are involved include evaluate report parameters, create a class in Microsoft Dynamics AX to use to manage the report parameters, and define access methods for the contract data elements. To understand the report parameters, follow these steps. 1. Take an inventory of the parameters used to manage the report. 2. Identify the elements of the parameter list that are used by the report business logic. 3. Determine the extended data typed (EDTs) that are used to format the data.

Demonstration: Create a Contract Class


To create a data contract class, follow these steps. 1. 2. 3. 4. Open Microsoft Dynamics AX. Open the Development Workspace. In the AOT, right-click the Classes node, and then click New Class. Right-click the new class that is created and then click Properties.

12-30

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


5. Locate the Name property and then type AOTObjectsContract. 6. Enter the following code sample into the Class Definition.
/// <summary> /// Data Contract class for the AOT Objects SSRS report /// </summary> /// <remarks> /// This is the Data Contract class for the AOT Objects SSRS report /// </remarks> [DataContractAttribute] public class AOTObjectsContract { Name parentNode; Name aotProperty; Name propertyVal; boolean incNoValue; }

Demonstration: Define Access Methods


Each report parameter must have a new method created that is decorated with the DataMemberAttribute. To create methods to manage each, parameter, follow these steps. 1. Locate the AOTObjectsContract node in the AOT 2. Open the class and add a method (by clicking the new icon) to manage the AOT Property input parameter. 3. Enter the following code sample into the new AOTProperty window.
/// <summary> /// Gets or sets the value of the datacontract parameter AOTProperty. /// </summary> /// <param name="_aotProperty"> /// The new value of the datacontract parameter AOTProperty; required. /// </param> /// <returns> /// The current value of datacontract parameter AOTProperty /// </returns> [ DataMemberAttribute('AOTProperty'), SysOperationLabelAttribute(literalstr("@SYS682'")) ] public Name parmAOTProperty(Name _aotProperty = aotProperty ) { aotProperty = _aotProperty; return aotProperty; }

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-31

Development IV in Microsoft Dynamics AX 2012


TIP: Notice the use of the literalstr() function and the "@" symbol when defining a label to be used for the SysOperationLabelAttribute. 4. Create a new method in the class by clicking the new icon. 5. Enter the following code sample for the Include no value parameter.
/// <summary> /// Gets or sets the value of the datacontract parameter IncludeNoValue. /// </summary> /// <param name="_incNoValue"> /// The new value of the datacontract parameter IncludeNoValue; required. /// </param> /// <returns> /// The current value of datacontract parameter IncludeNoValue /// </returns> [ DataMemberAttribute('IncludeNoValue'), SysOperationLabelAttribute(literalstr("@SYS53334")) ] public boolean parmIncNoValue(boolean _incNoValue = incNoValue ) { incNoValue = _incNoValue; return incNoValue; }

5. Create a new method in the class by clicking the new icon. 6. Enter the following code sample for the Parent node parameter.
/// <summary> /// Gets or sets the value of the datacontract parameter ParentNode. /// </summary> /// <param name="_parentNode"> /// The new value of the datacontract parameter ParentNode; required. /// </param> /// <returns> /// The current value of datacontract parameter ParentNode /// </returns> [ DataMemberAttribute('ParentNode'), SysOperationLabelAttribute(literalstr("@SYS58556")) ] public Name parmParentNode(Name _parentNode = parentNode ) { parentNode = _parentNode; return parentNode; }

7. Create a new method in the class by clicking the new icon. 8. Enter the following code sample for the Property value parameter.

12-32

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


/// <summary> /// Gets or sets the value of the datacontract parameter PropertyValue. /// </summary> /// <param name="_propertyVal"> /// The new value of the datacontract parameter PropertyValue; required. /// </param> /// <returns> /// The current value of datacontract parameter PropertyValue /// </returns> [ DataMemberAttribute('PropertyValue'), SysOperationLabelAttribute(literalstr("@SYS23425")) ] public Name parmPropertyValue(Name _propertyVal = propertyVal ) { propertyVal = _propertyVal; return propertyVal; }

Report Data Provider Classes


The Report Data Provider (RDP) class is the standardized interface that represents the data access point for the SSRS Reporting framework when X++ custom business logic is used to produce the dataset. The steps that are involved include the following: 1. Create a new class to manage custom business logic. 2. Add the two entry points for the RDP class. a. ProcessReport: This method is the entry point for processing the report dataset. b. getAOTObjectsTmp: This method is used by the framework to retrieve the report dataset from the temporary table cache. 3. Add all the custom business logic used to generate the report dataset.

Demonstration: Create a Report Data Provider Class


To create a RDP class, follow these steps. 1. 2. 3. 4. 5. 6. Open Microsoft Dynamics AX. Open the Development Workspace. In the AOT, right-click the Classes node, and then click New Class. Right-click the new class that is created and then click Properties. Locate the Name property and then type AOTObjectsDP. Enter the following code sample into the Class Declaration.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-33

Development IV in Microsoft Dynamics AX 2012


/// <summary> /// The Report data provider class that supports the AOT Objects report. /// </summary> /// <remarks> /// This class provides the methods that are used by the AOT Objects report /// </remarks> [ SRSReportParameterAttribute(classstr(AOTObjectsContract)) ] public class AOTObjectsDP extends SRSReportDataProviderBase { // temporary data store AOTObjectsTmp aotObjectsTmp; // contract information Name aotProperty; Name propertyVal; boolean incNoValue; }

Demonstration: Implement the Report Data Provider Class


To implement a RDP class, follow these steps. 1. Locate the AOTObjectsDP node in the AOT Classes node. 2. Open the class and add custom business logic. In this demonstration, you will import the code from an XPO on the Hyper-V image. To import the file, follow these steps. 1. 2. 3. 4. 5. 6. 7. Open Microsoft Dynamics AX. Open the Development Workspace. In the AOT click the Import icon or press CTRL+SHIFT+I. In the Import dialog box, click Browse. Browse to the AX2012_ENUS_DEVIV_12_01_LAB.xpo file. Click Open. On the Import dialog box, click OK.

Create an SSRS Report from an RDP Class


The following demonstration explains how to create a RDP bound dataset that exposes AOT Object information in a Precision design report. The steps involved include: 1. Create a new report in Visual Studio 2010. 2. Create a new Data set for the report tied to the new RDP class.

12-34

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


3. Create a basic view of the report data grouped on the AOT Object Property information. 4. Convert the basic design into a Precision Design to achieve the desired report layout.

Demonstration: Create a Report in Visual Studio 2010


To create a reporting project, follow these steps: 1. Open Microsoft Dynamics AX. 2. Open the Development Workspace. 3. Locate the project that you created in the Create a New Report in Visual Studio demonstration in the AOT under Visual Studio Projects > Dynamics AX Model Projects node. 4. Right-click the project, and then click Edit. This opens the report project in Visual Studio. 5. In the Solution Explorer, click the Add button and select Report. An empty report model named Report1 is created. 6. Right-click the newly created report and rename it to AOTObjects_WS2. To create a RDP based dataset, follow these steps: 1. 2. 3. 4. Expand the AOTObjects_WS2 node if it is not already expanded. Right-click the Datasets node, and then click Add Dataset. Select the node for the dataset. In the Properties window, specify the following values: a. Data Source = Dynamics AX b. Data Source Type = Report Data Provider c. Default Layout = Table d. Name = AOTObjectsDS e. Query = Select * from AOTObjectsDP.AOTObjectsTmp

To create a precision design to match desired layout, follow these steps: 1. In the Model Editor, select the AOTObjectsDS node and drag it onto the Designs node. An auto design named AutoDesign1 is created for the report. 2. Right-click the AutoDesign1 node, and then click Preview. 3. Set the LayoutTemplate & TableStyleTemplate properties to define the report visual settings. 4. Group the report dataset on the =Fields!Property.Value. 5. Right-click the AutoDesign1 node, and then click Create Precision Design. 6. Right-click the PrecisionDesign1 node, then click Rename, and set the name to Report.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-35

Development IV in Microsoft Dynamics AX 2012


Now you have created a Precision Design that produces the same output as the Auto Design automatically created to match the report dataset. Notice that this layout is inconsistent with the desired look for the final report. The next step is to use the Visual Studio tools to manipulate the design match the expected report output.

Manage Report Execution by Using X++


In Microsoft Dynamics AX, you can execute and manage Visual Studio Reporting Tools for Microsoft Dynamics AX reports by using X++. This lesson shows how to print a report, set the print settings, prevent the display of print setup, set the query range, and set a report parameter value.

Procedure: Print a Report from X++


In Microsoft Dynamics AX, you can print reports that are created by using Visual Studio Reporting Tools for Microsoft Dynamics AX. This topic provides the prerequisite steps for how to print a report, how to print from a menu item, and how to print a report programmatically. The SrsReportRunInterface class is an interface class that provides a set of APIs to integrate running a report programmatically. This interface should be used when you want to run a report from your form or code. Application developers who want to take complete control over the rendering and running of a report should use these APIs. Some examples of how or why this class can be used include the following. Custom form that needs to run the report. Custom implementation of the Controller class of the SysOperation framework. Batch printingan example is to iterate over each customer record and print the invoice for the customer. Change the report design that is being used at runtime. Change the culture or company that is being used at runtime.

Prerequisites to Print a Report


The prerequisites to print a report include the following. The report must be saved and deployed to the report server. There must be a way to access the report either programmatically or from a menu item.

12-36

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Print a Report from a Menu Item
To print a report from a menu item, follow these steps. 1. Open a menu item that corresponds to the report that you want to print. 2. Set the parameters that exist. a. If you have queries, click the Select button and set the range. b. Click the Destinations button to set the print destination fields. You can print to a screen, printer, file, or email recipient. 3. Click OK to print the report.

Print a Report Programmatically


1. In the AOT, find the code element that you want to print the report from. 2. Right-click the code element and then click Edit. 3. Use the following code samples to print a report directly or to open the report dialog from code.
///Declare a variable SrsReportRunInterface reportRun;

//Create an instance of the report //Pass in the report that you want to run by using the format // '<ReportName>.<DesignName>' reportRun = new SrsReportRunImpl('CustBaseData.Report'); // Run the report. reportRun.runReport();

NOTE: This example runs a simple report that does not have a modified contract. TIP: In a more complex example where the report uses a data contract class, additional code will be required. For an example of how to implement this, refer to the EPSendDocument class makeDocument() method. This class is designed to print a different report based on the record that is passed in.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-37

Development IV in Microsoft Dynamics AX 2012


Procedure: Define the Print Settings
In Microsoft Dynamics AX, you can programmatically change the print settings for a report. Print settings are implemented as the various properties on the SRSPrintDestinationSettings object. You can create your own SRSPrintDestinationSettings object and assign it to the SrsReportRunInterface object or you can use the default print setting values and modify specific settings. The following example uses the default settings and updates specific settings. The report will be printed to file together with the file name set to ReportExample.
Args args; SrsReportRunInterface reportRun; SrsReportDataContract contract; SRSPrintDestinationSettings printSettings; //Instantiate args and pass in the record that you have args = new Args(); args.record(record); //Create an instance of the contract for the desired report. //This example used the sales order quotation report. contract = SalesQuotationController::newDataContract(args); if (contract != null && contract.parmReportName()) { //Create an instance of the report reportRun = new SrsReportRunImpl(contract.parmReportName()); //Set the contract parameter in the report instance reportRun.parmReportContract(contract); //Set the desired printer options printSettings = reportRun.parmReportContract().parmPrintSettings(); printSettings.printMediumType(SRSPrintMediumType::File); printSettings.fileFormat(SRSReportFileFormat::PDF); printSettings.fileName(file); printSettings.overwriteFile(true); // Run the report. reportRun.runReport(); }

12-38

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Demonstration: Set the Query Range on a Report
This topic describes how to set a data source range value for a report query in Microsoft Dynamics AX X++ code. A query is one of several ways to retrieve data for a report that is created with Visual Studio reporting tools for Microsoft Dynamics AX. In this example the Customer base data report will be run for a specific customer. 1. Create a new controller class for the CustBaseData report that extends SrsReportRunController. Use the following code sample to guide you. class CustBaseDataController extends SrsReportRunController { } 2. Next, create a new method called setRanges that set the report ranges based on a query that is passed in. Use the following code sample to guide you. /// <summary> /// Sets the report query ranges based on caller. /// </summary> /// <param name="_query"> /// Report query object. /// </param> public void setRanges(Query _query) { QueryBuildDataSource queryBuildDataSource; str range; custTable custTable; custTable = this.parmArgs().record(); queryBuildDataSource = _query.dataSourceTable(tableNum(custTable)); range = queryValue(custTable.AccountNum); //Adding the account number to the range value SysQuery::findOrCreateRange(queryBuildDataSource, fieldNum(custTable, AccountNum)).value(range); } 3. Next, create a new method that overrides the preRunModifyContract method. Use the following code sample to guide you. protected void preRunModifyContract() { Query q; QueryBuildRange qbr; QueryBuildDataSource qbds;

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-39

Development IV in Microsoft Dynamics AX 2012


AccountNum accountnum; CustTable custTable; custTable = args.record(); accountnum = custTable.AccountNum; q = this.getFirstQuery(); qbds = q.dataSourceTable(tableNum(custTable)); if (AccountNum) { qbr = qbds.addRange(fieldNum(CustTable, AccountNum)); qbr.value(queryValue(AccountNum)); } } 4. Next, override the prePromptModifyContract method. Use the following code sample to guide you. protected void prePromptModifyContract() { this.setRanges(this.parmReportContract().parmQueryContracts().lookup(this.get FirstQueryContractKey())); } 5. Next override the main method. Use the following code sample to guide you. public static void main(Args _args) { CustBaseDataController controller = new CustBaseDataController(); controller.parmReportName(ssrsReportStr(CustBaseData, Report)); controller.parmArgs(_args); controller.startOperation(); } NOTE: The CustBaseData report already has a controller class called smmReportsController that is designed to handle several reports. You could modify that class to contain the logic required.

12-40

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


At this point you have created a controller for the report. Now you must create some logic to programmatically run the report and override the query. In this example a job is created to call the report. Use the following code sample to guide you.
static void ReportWithQueryOverride_SampleJob() { // Create variables for setting the range for the query. Args args; CustTable tCustTable; // Create an instance of a report. CustBaseDataController cbdController; cbdController = new CustBaseDataController(); tCustTable = CustTable::find('4001'); // Create an instance of args and set the record to the selected customer args = new args(); args.record(tCustTable); // Set the full name of the report. cbdController.parmReportName('CustBaseData.Report'); // Set args parameter in the class to the args instance you created cbdController.parmArgs(args); // Run the report cbdController.startOperation(); }

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-41

Development IV in Microsoft Dynamics AX 2012


When you are finished creating the job, save, compile, and then run the job. The report dialog will open and you should notice that the customer account 4001 is already entered into the report query selection. If you click OK and run the report the report should only print data for customer 4001.

FIGURE 12.11 CUSTBASEDATA.REPORT DIALOG BOX

Demonstration: Prevent Display a Report Dialog


In some instances a report can contain sensitive information that requires it be printed to a secure printer. In another example, you may not want the dialog to appear because we are assuming the parameters are already set and no user interaction is required. This topic shows how to print from a secure printer. To hide the report dialog for a report with the library report that contains sensitive data, add the following code in the Code Editor. This example uses the same job that was used in the "Set the Query Range on a Report" demonstration.
static void ReportWithQueryOverride_SampleJob() { // Create variables for setting the range for the query. Args args; CustTable tCustTable; // Create an instance of a report. CustBaseDataController cbdController; cbdController = new CustBaseDataController(); tCustTable = CustTable::find('4001'); // Create an instance of args and set the record to the selected customer args = new args(); args.record(tCustTable); // Set the full name of the report. cbdController.parmReportName('CustBaseData.Report'); // Set args parameter in the class to the args instance you created cbdController.parmArgs(args);

12-42

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


// Hide the report dialog box cbdController.parmShowDialog(false); // Run the report cbdController.startOperation(); }

TIP: Other methods are available to hide various objects within the reporting framework. For example, if you want to hide the report dialog box you can call the showDialog() method and pass in false to set the value. For a complete list of methods and their functionality, refer to the developer help on MSDN.

Business Logic in Report Data Methods


When you create reports in a reporting project in Microsoft Visual Studio, you can use data methods to retrieve and manipulate the data that displays in your reports. Each reporting project contains a nested business logic project. When you create a data method within the Model Editor, a template for the data method is copied into a code file within the nested business logic project. To view the code for a data method, follow these steps. 1. Right-click the data method in the Model Editor. 2. Click View Code, or double-click the code file in Solution Explorer. The name of the data method and all other properties in the Model Editor are automatically updated as you change the code. When you build a business logic project, the code is compiled into a business logic assembly (.BusinessLogic.dll). During deployment, business logic assemblies are built and deployed to the report server and the security policy file for the report server is updated so that .NET Business Connector has secure access to the assemblies.

Structure of a Data Method


A data method contains the [DataMethod()] attribute, and only methods with this attribute are recognized as data methods by the reporting tools. A data method, such as a query, can be used as a source of data for a report dataset, and within report expressions to perform data manipulations or calculations for fields that display in the report. You must build the business logic project that contains your data methods before you can use the data methods in your report. The return value for a data method can be any .NET type. The default return value is a System.String instance. To use a data method as a source of data for a report dataset, it must return an IEnumerable<DataRow> or System.Data.DataTable instance.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-43

Development IV in Microsoft Dynamics AX 2012


The following C# code shows an example of a data method called RetrieveItemData that returns a System.Data.DataTable instance. This example returns the InventTable.
[DataMethod(), AxSessionPermission(SecurityAction.Assert)] public static IEnumerable<DataRow> RetrieveItemData() { // Retrieve records from the InventTable table. return AxQuery.ExecuteQueryStream("select * from InventTable"); }

TIP: To use the code sample provided, create a new SSRS report in Visual Studio. Next, create a data method with the code sample provided, and then create a new Data Set. Make sure that you set the Data Source Type property to Business Logic, and then in the Query property select the RetrieveItemData method that you created. Then you must design the report. When you are finished you can preview the report. Data methods can have parameters. A parameter for a data method can be any .NET type. When a data method is used in a dataset, a report parameter is automatically generated for each parameter in the data method. Report parameters display below the Parameters node in the Model Editor. The following scenarios are not supported in data methods. Overloading data methods is not supported. You can have only one data method of a particular name inside a model. If you overload a data method, you will receive an error stating that multiple data methods with the specified name exist, and you will be unable to use the data method within the report. Sharing data methods between reporting projects. Accessing Microsoft Dynamics AX queries by using data. Use a report data provider class to access a Microsoft Dynamics AX query in a report.

Data Methods in Report Expressions


The code for an expression is embedded within the report and it is not compiled into the business logic assembly. Data methods can be used inside an expression. In this case, the expression references the data method in the business logic assembly. The Expression Editor displays a list of data methods that are available to the report.

12-44

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


For business logic that is more complex, the recommendation is to write the business logic inside a data method, and then call the data method from an expression. By doing this you can take advantage of the capabilities of a full programming language when writing your business logic. You can reference types that are defined in other assemblies. For example, you can reference a .NET Framework assembly, and then use an existing .NET type inside your business logic. You can call other methods from inside a data method, as shown in the previous code example. Additionally, you can access X++ code that is defined in Microsoft Dynamics AX by using the managed programming interface for reports that are defined in the [N:Microsoft.Dynamics.Framework.Reports] namespace. A data method can be used in multiple expressions inside a report, so that the business logic that you define inside a data method is reusable within the report. Expressions are not reusable inside a report. When you create an expression, it cannot be called from another expression within the report.

Modifying and Deleting Data Methods


You can delete a data method in the Model Editor or directly in the code. When you delete a data method in the Model Editor, the [DataMethod()] attribute is removed from the data method. The rest of the code for the data method remains in the code file. You can manually remove the code if it is no longer needed. All other changes to a data method must be made directly in the code. For example, you cannot change the name of a data method in the Model Editor or in the Properties window. Instead, you must change the name of the data method directly in the code. As soon as you make a change in the code, the Model Editor and the properties that display in the Properties window are automatically updated to reflect what is in the code. NOTE: Model refactoring is currently not supported for data methods. The model refactoring options are disabled on the context menu that displays for a data method in the Model Editor. You must be careful when you modify data methods. Data methods can be referenced from data sets and expressions throughout a report. If you make a breaking change to a data method in the code, you must manually update all references to the data method wherever it is used in the report. The following actions can result in a breaking change and cause errors in your report. Deleting a data method Removing the [DataMethod()] attribute from the data method Changing the name of a data method Changing the return value of a data method Adding or removing parameters in a data method Changing the type of a parameter in a data method

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-45

Development IV in Microsoft Dynamics AX 2012


Model validation is used to help identify broken references and invalid expressions. When you build a project, error messages for broken references and invalid expressions display in the Error List window. NOTE: For more information about how to use business logic in report data methods to access report data refer to MSDN (http://go.microsoft.com/fwlink/?LinkId=238177).

Print Management
Print management gives users control of print settings for selected Microsoft Dynamics AX reports. Print settings include the number of copies, the printer destination, and the multilanguage text that can be included on the report. Some additional print management features that you can use include the following. Modify the print settings of a report that is based on the contents of the data being printed. For example, send sales orders greater than 1000 U.S. dollars (USD) to Printer A and sales orders greater than 10,000 USD to Printer B. Specify print settings at various levels of the application. For example, module-level print settings apply to all documents in a given module, whereas customer-level print settings only apply to specific customers and transaction-level print settings apply only to specific transactions. Override or add to the settings from higher levels in the application. For example, module-level settings can be overridden at the customer or transaction level if not desirable. Moreover, additional settings can be added to the existing settings for similar reasons.

Why Use Print Management?


You should consider by using the print management framework when the following conditions are true: Your new or existing feature has reports that require specialized print management. You are adding a new document type to the application that resembles the document types currently supported by print management.

12-46

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Architectural Overview
The print management subsystem is divided into three main parts: metadata, setup, and retrieval. Metadata defines a series of classes that you can use to describe how print management should work. You can describe how many levels of defaulting are possible, what tables and columns should be involved in queries, and other pertinent information. Setup defines a generic user experience that can be opened throughout the application that is based on certain inputs. You would call this in areas where print management information must be managed by end-users. Retrieval defines an Application Programming Interface (API) which you can use to retrieve and use the print management information set up by the user.

FIGURE 12.12 PRINT MANAGEMENT FLOW

Defining Metadata
Print management metadata is defined completely in code and originates from four main classes or concepts: PrintMgmtDocType (documents), PrintMgmtNode (nodes), PrintMgmtHierarchy (hierarchies), and PrintMgmtReportFormat (formats). A document is the document or report to which specific print management settings apply. Documents are the core of print management because all settings are defined for documents of a particular type. When users set up this information, it is used when that document is printed. The documents in the print management system are defined in the PrintMgmtDocType class and are always related to specific nodes in print management. A node is a particular level of defaulting in a hierarchy. For example, in the Accounts Receivable module print management settings can exist at the Sales Order Transaction level, the Customer level and the Module level. Each of these levels is considered a node and each node in print management must derive from the abstract PrintMgmtNode class. While nodes define the level at which print management settings can exist, they have no order by themselves which is where hierarchies help.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-47

Development IV in Microsoft Dynamics AX 2012


A hierarchy is a group of related nodes. By using the previous example, the nodes mentioned would all be a part of the Account Receivable hierarchy. The ordering of nodes in a hierarchy defines the ordering of defaulting for print management settings. Each hierarchy in print management must derive from the abstract PrintMgmtHierarchy class. A report format is the design or layout of the report. It is possible for each report to have multiple designs. The following diagram shows how documents, nodes and hierarchies all relate to one another to define the print management metadata for a hypothetical Accounts Receivable hierarchy.

FIGURE 12.13 PRINT MANAGEMENT DOCUMENT-NODE-HIERARCHY SAMPLE

The Accounts Receivable node represents the module level settings and all documents present in the module apply at this level. The Customer node represents settings that apply to specific customers and all documents present in the module apply. At the lowest level the nodes represent transaction level settings and only certain documents apply to each specific transaction. Sometimes to integrate with print management, you might have to modify existing nodes or hierarchies to meet the needs of the documents that you want to print. You might also be required to create new nodes, hierarchies or documents to accomplish the same goal. The following sections outline the steps that are required to accomplish these common integration tasks.

12-48

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


Adding a New Document
Whether you are adding a new document to new or existing nodes the same steps are required. To better understand the classes or methods mentioned in the steps, refer to the XML documentation that is included in the source code. 1. Update the PrintMgmtDocumentType enumeration Add the document type to the enumeration immediately following the last element. Create and assign a label for the document type that follows the pattern for existing document types. 2. Update the PrintMgmtDocType class to handle the new document type. o Modify the getQueryTableId method. Add the table ID of the table that will be used when enabling users to enter conditional queries for the document type. This is generally the "Jour" (journal) table that is used when you post, but could be any table that applies. o Modify the getQueryRangeFields method. Add the default fields that should be used when entering conditional queries for the new document type. The order in which they are added will also be the order in which they appear in the Query window. Consider wrapping this logic with a call to isConfigurationkeyEnabled, passing the appropriate configuration key, to guarantee that the fields only appear when the functionality is enabled in the system. o Modify the getDefaultReportFormat method. Add a case for the document type and return the name of the base SSRS report. Remember to use the ssrsReportStr() intrinsic function to make sure that the report name is validated at compile time. 3. Update the PrintMgmtDocTypeTest class to handle the new document type. o Modify the testGetDisplayName method. Add a test to guarantee that the document type appears with the correct text. o Modify the testGetQueryTableId method. Add a test to guarantee that the document type has the correct query table id. o Modify the testGetQueryRangeFields method. Add a test to guarantee that the document type has the correct default query fields. 4. Update all PrintMgmtNode derivatives to which the document type applies. o Modify the getDocumentTypes method. Add the document type to the list of supported document types. o Wrap this logic with a call to isConfigurationkeyEnabled, passing the appropriate configuration key, to guarantee that the documents only appear when the functionality is enabled in the system.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-49

Development IV in Microsoft Dynamics AX 2012


5. Update necessary PrintMgmtNode derivatives tests for the document type. o Modify the testNodeDocumentTypes method. o Create or update this method to handle the document type. 6. Update necessary PrintMgmtHierarchy derivatives to which the document type applies. o Modify the getParentImplementation method. This method is used to define the structure of the nodes in a hierarchy. In some cases, the document type affects the logic to determine the parent and in other cases it does not. For example, Sales order invoice documents use the InvoiceAccount field of the SalesTable to find their parent node, whereas Sales order confirmation documents use the CustAccount field of the SalesTable. This is all determined based on the document type. o If your new document type requires special behavior such as this, update the method. 7. Update necessary PrintMgmtHierarchy derivatives tests for the document type. o This step is only necessary if you were required to update the getParentImplementation method. o Update the testGetParent method. Add tests for the new document type following the existing pattern. o Update the testGetParentSkippingLevels method. Add tests for the new document type following the existing pattern. 8. Update the PrintMgmtReportFormat tables populate method. o Add a call to AddAx(PrintMgmtDocumentType _type, PrintMgmtReportFormatCountryRegionId _countryRegionId = #NoCountryRegionId) for the new document type and optionally the country or region with which the report is specifically associated.

Create or Modify Nodes


New nodes are necessary when a new level of defaulting is necessary for the documents you want to print. If you want a better understanding of the classes or methods mentioned in the steps, see the XML documentation that is included in the source code. 1. Make sure a node does not already exist that meets your needs. Look at the classes that derive from the PrintMgmtNode class to determine this information. Even if an existing node defines document types that you are not interested in using, you can still use the node. If the existing nodes do not meet your needs, continue to step 2. 2. Create a new enumeration value in the PrintMgmtNodeType enumeration.

12-50

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


o o Add the node type to the enumeration immediately following the last element. The name of the element should match the table to which the print management settings will be related. If the print management settings do not relate to a table, choose a name following the existing patterns present. Create and assign a label for the node type. If the node references a table, use the table name label from the table it references. If not, follow the existing patterns present.

3. Create a new class that derives from the PrintMgmtNode class. Make sure that you reference the existing PrintMgmtNode derivatives for examples. The class should be prefixed with 'PrintMgmtNode_' and should follow the naming pattern of the existing nodes. If the node is tied to a particular table, the table name should follow the prefix such as PrintMgmtNode_CustTable, for example. o Implement the getDisplayCaptionImplementation method. o o This method controls the caption that will appear for the instance of the node in the Print Management window. Return the appropriate label for Module level settings. Refer to existing examples in PrintMgmtNode_Purch or PrintMgmtNode_Sales. Return strfmt("@SYS108943", _tableBuffer.caption()) for account level settings. Refer to the existing example in PrintMgmtNode_CustTable or PrintMgmtNode_VendTable. Return strfmt("@SYS108944", _tableBuffer.caption()) for transaction level settings. Refer to existing examples in PrintMgmtNode_SalesTable or PrintMgmtNode_PurchTable. Customize as necessary for unique situations.

o o

Implement the getDocumentTypes method. o o Return a list of document types the node supports. The document types should be wrapped in configuration key checks so that they are only loaded if the configuration key is enabled. For example, isConfigurationkeyEnabled(configurationkeynum(Logist icsBasic)).

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-51

Development IV in Microsoft Dynamics AX 2012


o Implement the getIconImageResNum method. o o This method controls the icon that will appear for the instance of the node in the Print Management window. Return the resource ID used to display the icon representing this node. The resAppl macro contains the resource ID definitions for icon images. This method should return one of those resource IDs. If additional resource IDs are used, they should also be added to the build method of the ImageListAppl_PrintMgmt class. Module level nodes should use the same icon that is used for the module, account level nodes should use #ImagePrintManagementAccount, and transaction level nodes should use #ImagePrintManagementTrans.

Implement the getNodeType method. o Return the appropriate PrintMgmtNodeType enumeration value.

Implement the getReferenceTableId method. o Return the table to which the node will be related. For example, if a node is tied to specific customers that you would return tablenum(CustTable). If the node is not related to a specific table, return the value of 0. Module level settings are examples of nodes that are not tied to specific tables.

4. Modify the PrintMgmtNode::construct method. Add a case statement to construct your new node. 5. Create appropriate unit tests. o o The name of the test class should be identical to the node followed by the postfix 'Test'. About the contents of the tests, follow the example of existing node tests that resemble your node type. For example, modulelevel, account level, transaction level nodes, or other. To add data, follow the existing examples in the PrintMgmtTestSuite class. o Add a macro that defines the ID of the table in the classDeclaration. o Add a new method that retrieves the table following the existing pattern. For example, getSalesTable, getCustInvoiceTable, and so on.

12-52

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


o Create the data in the setUpReferenceData method and make to trackInsertedRows for the table that you add. As soon as you have finished, add the new test to the PrintMgmtTestSuite by adding the appropriate entry in the new method.

6. If the node relates to a table, update the appropriate relations and cascading deletes. o Create a relation on the PrintMgmtDocInstance table to the table that you are referencing. For example, PrintMgmtDocInstance > SalesTable. Add a cascading delete action on the table that you are referencing to the PrintMgmtDocInstance table. For example, SalesTable > PrintMgmtDocInstance.

7. Add the node to the appropriate hierarchy. See the Create or Modify Hierarchies section for the steps that are required to perform this action. 8. Add the node to the PrintMgmt shared project.

Create or Modify Hierarchies


Sometimes existing hierarchies can be modified to include or rearrange existing nodes, and sometimes completely new hierarchies are necessary. Both scenarios have similar steps that are described later in this training material. To better understand the classes or methods mentioned in the steps, refer to the XML documentation that is included in the source code. 1. Create a new enumeration value in the PrintMgmtHierarchyType enumeration. o Add the hierarchy type to the enumeration immediately following the last element. o Create and assign a label for the hierarchy type following the existing patterns. 2. Create a new class that derives from the PrintMgmtHierarchy class. Make sure that you reference the existing PrintMgmtHierarchy derivatives for examples. o o The class should be prefixed with 'PrintMgmtHierarchy_' and should follow the naming pattern of the existing hierarchies. Implement the getNodesImplementation method. o Return the list of nodes the hierarchy supports.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-53

Development IV in Microsoft Dynamics AX 2012


o Implement the getParentImplementation method. o This method is used to define the structure of the nodes in a hierarchy. It provides an instance of a node and a document type as input parameters and will be required to return an instance of the PrintMgmtNodeInstance class. This PrintMgmtNodeInstance class brings together a PrintMgmtNode instance with the actual table buffer record it relates with. If the parent node does not reference a table, only the PrintMgmtNodeType enumeration value of the parent is required to be returned through the parmNodeDefinition property of the PrintMgmtNodeInstance class. If the parent node does reference a table, the specific record of the parent node should be returned also. This is returned through the parmReferencedTable property of the PrintMgmtNodeInstance class. If the record cannot be found, a null value should be returned. Refer to existing implementations for a better understanding of what is necessary for this method.

3. Modify the PrintMgmtHierarchy::construct method. Add a case statement to construct your new hierarchy. 4. Create appropriate unit tests. o o o The name of the test class should be identical to the hierarchy followed by the postfix 'Test'. About the contents of the tests, follow the example of existing hierarchy tests. To add data, follow the existing examples in the PrintMgmtTestSuite class. o

Add a macro that defines the ID of the table in the classDeclaration. o Add a new method that retrieves the table following the existing pattern. For example, getSalesTable or getCustInvoiceTable. o Create the data in the setUpReferenceData method and make sure that you trackInsertedRows for the table that you add. As soon as you are finished, add the new test to the PrintMgmtTestSuite by adding the appropriate entry in the new method. 5. If you are modifying an existing hierarchy, make sure that you update the appropriate hierarchy tests. Modify the testIsValidNodeType method. Update the count because the number of nodes added will have changed. 6. Add the hierarchy to the PrintMgmt shared project.

12-54

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


A custom format is a modification of an existing SSRS report as managed by Print Management that the user can select by using Print Management setup. The basic steps for developing this include the following. Copy an existing SSRS report (the .RDL file) with a new name. Modify the new SSRS report layout by moving, deleting, or adding report elements. Add a call in table PrintMgmtReport formats populate method to the addOther() method. Call the table method PrintMgmtReportFormat::populate to update the table with the new report format so it is available to the user to select in Print Management setup.

Summary
This chapter introduced the features of SSRS and demonstrated how to create a simple report by using a query and an auto-design. Additionally, the chapter showed how you can use the report data provider framework to deliver business logic to a report in more complex business scenarios. The MVC is a pattern used to separate the data (Model) from the user interface (View) and the business logic (Controller) is used to communicate between the Model and the View. You can implement this framework by decorating your classes together with attributes such as the DataContractAttribute and the DataMemberAttribute. You can use the SRSReportRun framework to control how the printing and output of a report will be handled. You can also use X++ to set parameter values when running a report. In addition to the query framework and the report data provider framework, you can use business logic in Visual Studio to retrieve the data for a report. To use business logic in a report you must create a data method that includes the DataMethhod() attribute. A data method can also be used within report expressions to perform data manipulations or calculations for fields that display in the report. Developers can implement print management for selected Microsoft Dynamics AX reports. This gives users control of print settings. A developer must create or modify the document, node, and hierarchy for each report that you want to enable print management for.

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-55

Development IV in Microsoft Dynamics AX 2012

Test Your Knowledge


Test your knowledge with the following questions. 1. Put the following steps in the correct order to create a new SSRS report from a Microsoft Dynamics AX query: Step: _____: Apply style templates. _____: Create a new report model in Visual Studio. _____: Add field data to the query. _____: Create a new query in the AOT. _____: Create a report design. _____: Create a report dataset. 2. Which of the following is not a feature of reporting in Microsoft Dynamics AX 2012? ( ) Deployment by using PowerShell scripts. ( ) Support to submit a report to the batch processor. ( ) MorphX report designer in the Application Object Tree. ( ) Support to use labels in a report design to provide support for multiple languages for the same report. 3. What must you create to store the data when a report data provider class is used for the data set? ( ) A persisted table in SQL ( ) An in-memory temporary table in the AOT ( ) A persisted table in the AOT ( ) A temporary table in SQL 4. Which of the following options is not a class that is used for implementing print management on a new report? ( ) PrintMgmtDocType ( ) PrintMgmtHierarchy ( ) PrintMgmtReport ( ) PrintMgmtNode

12-56

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting


5. Categorize the reporting dataset options with the data sources: Categories (Data Source): 1. Dynamics AX 2. SQL 3. Dynamics AX OLAP _____ Item 1: MDX Query _____ Item 2: Queries in the AOT _____ Item 3: TSQL _____ Item 4: Report Data Provider class _____ Item 5: Stored Procedure _____ Item 6: Data methods 6. Which of the following is not a step in the process for saving and deploying a report project? ( ) Rebuild the solution ( ) Save the report to the AOT ( ) Import the report into the AOT ( ) Deploy the report

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-57

Development IV in Microsoft Dynamics AX 2012

Quick Interaction: Lessons Learned


Take a moment and write down three key points you have learned from this chapter 1.

2.

3.

12-58

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Chapter 12: Reporting

Solutions
Test Your Knowledge
1. Put the following steps in the correct order to create a new SSRS report from a Microsoft Dynamics AX query: Step: 6 3 2 1 5 4 : Apply style templates. : Create a new report model in Visual Studio. : Add field data to the query. : Create a new query in the AOT. : Create a report design. : Create a report dataset.

2. Which of the following is not a feature of reporting in Microsoft Dynamics AX 2012? ( ) Deployment by using PowerShell scripts. ( ) Support to submit a report to the batch processor. () MorphX report designer in the Application Object Tree. ( ) Support to use labels in a report design to provide support for multiple languages for the same report. 3. What must you create to store the data when a report data provider class is used for the data set? ( ) A persisted table in SQL () An in-memory temporary table in the AOT ( ) A persisted table in the AOT ( ) A temporary table in SQL 4. Which of the following options is not a class that is used for implementing print management on a new report? ( ) PrintMgmtDocType ( ) PrintMgmtHierarchy () PrintMgmtReport ( ) PrintMgmtNode

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

12-59

Development IV in Microsoft Dynamics AX 2012


5. Categorize the reporting dataset options with the data sources: Categories (Data Source): 1. Dynamics AX 2. SQL 3. Dynamics AX OLAP 3 1 2 1 2 1 Item 1: MDX Query Item 2: Queries in the AOT Item 3: TSQL Item 4: Report Data Provider class Item 5: Stored Procedure Item 6: Data methods

6. Which of the following is not a step in the process for saving and deploying a report project? ( ) Rebuild the solution ( ) Save the report to the AOT () Import the report into the AOT ( ) Deploy the report

12-60

Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement

Вам также может понравиться