Lab 2.2: Create a Report with X++ Business Logic

advertisement
Chapter 2: SQL Server Reporting Services
CHAPTER 2: SQL SERVER REPORTING SERVICES
Objectives
The objectives are:

Describe the installation procedure and prerequisites.

Identify the tools that are used to develop and deploy reports for
Microsoft Dynamics® AX 2012.

Explain the process for developing reports by using Visual Studio.

Review the three options to deploy reports.

Describe how SSRS reports can be used within Microsoft Dynamics
AX 2012.
Introduction
SQL Server Reporting Services (SSRS) is the primary framework for developing
reports in Microsoft Dynamics AX 2012. The installation requirements include
completing tasks such as verifying prerequisite components are installed,
completing the installation setup wizard and deploying default reports. With
SSRS, users can develop and deploy reports and integrate reports with Microsoft
Dynamics AX 2012.
2-1
Reporting in Microsoft Dynamics® AX 2012
SSRS provides data that can be displayed in many different clients including:
Microsoft Dynamics AX clients, Enterprise Portal, and batch jobs.
FIGURE 2.1 MICROSOFT DYNAMICS AX 2012 REPORTING FRAMEWORK
2-2
Chapter 2: SQL Server Reporting Services
Using SSRS with Microsoft Dynamics AX 2012 provides users professionallooking reports, more export formats, and a more capable report designer. When
you use SSRS for developing Microsoft Dynamics AX 2012 reports it results in
the following benefits:

Increased use of the Microsoft technology stack

Business logic is kept in Microsoft Dynamics AX 2012

Smooth transition for X++ and C# developers to the new reporting
architecture
All the standard reports that are provided with Microsoft Dynamics AX 2012 use
the SSRS reporting framework. When you upgrade from an earlier version of
Microsoft Dynamics AX, legacy reports and cubes are not upgraded. Reports that
use 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.
Installation
Microsoft SQL Server Reporting Services (SSRS) is installed as part of the SQL
Server installation. Microsoft Dynamics AX 2012 employs Reporting Services
Extensions to make use of SSRS capabilities. The Reporting Services Extensions
are installed and configured as part of the Business Intelligence installation
during the Microsoft Dynamics AX 2012 installation. Refer to the Microsoft
Dynamics AX 2012 Installation Guide for more information. The Business
Intelligence components can be installed separately if they were not installed
during the Microsoft Dynamics AX 2012 installation.
Prerequisites
Before you install the Business Intelligence components, check that the
prerequisites are met. Run the Microsoft Dynamics AX prerequisite validation
utility to determine whether a computer meets the requirements to install a
Microsoft Dynamics AX component.
Specific requirements for installing Reporting Services extensions include the
following:

Microsoft SQL Server 2008 Reporting Services

Microsoft SQL Server 2008 R2, Cumulative Update 3 or a later
version

Windows PowerShell 2.0
Refer to the Microsoft Dynamics AX 2012 System Requirements document for
more information.
To install the Reporting Services Extensions, you must be a member of the
System administrator role in Microsoft Dynamics AX. Reporting Services
extensions must be installed on the computer that is running SSRS.
2-3
Reporting in Microsoft Dynamics® AX 2012
Installation
To install the Business Intelligence components, run the Microsoft Dynamics AX
2012 setup. Refer to the Microsoft Dynamics AX 2012 Installation Guide for
more information. The installation setup wizard will perform the following
actions:

Verify that prerequisite software is installed on the server

Install SQL Server Reporting Services extensions

Deploy the default reports that are included with Microsoft
Dynamics AX 2012

Configure SQL Server Analysis Services
If the default reports are not deployed during the installation, they can be
deployed later using Windows PowerShell.
Deploy Default Reports
Microsoft Dynamics AX 2012 includes default reports that must be deployed to
Microsoft SQL Server before they can be used. The default reports can be
deployed during the Reporting services installation by using the Microsoft
Dynamics AX 2012 setup.
If you did not deploy the reports when you installed the Reporting Services
extensions, you can deploy them by using Windows PowerShell. The following
procedures can help you deploy the reports:
1. Open PowerShell and view a list of reports
2. Filter the list of reports
3. Deploy the reports
Open PowerShell and View a List of Reports
Complete the following procedure to open PowerShell and view a list of the
reports that are included with Microsoft Dynamics AX 2012.
1. Open PowerShell as an administrator by clicking Start >
Administrative Tools.
2. Right-click the Microsoft Dynamics AX 2012 Management Shell
option.
3. Click Run as administrator.
4. Retrieve default reports that are included with Microsoft Dynamics
AX, and store the list in a local variable using the following
command: $reports = Get-AXReport -ReportName *
2-4
Chapter 2: SQL Server Reporting Services
5. View the list of reports by entering the following command: $reports
FIGURE 2.2 WINDOWS POWERSHELL
Filter the List of Reports
To modify and filter the list of default reports use the following commands:

To modify the list so that only the Name and ChangedDate fields
are displayed, enter the following command: $reports | Select-Object
Name,ChangedDate

To filter the list so that only specific reports are listed, enter
keywords or report names. For example, to filter the list so that only
reports that contain the word CustTrans are listed, enter the
following command: $reports | Select-Object Name,ChangedDate |
Where { $_.Name -like "CustTrans*" }
Deploy the Reports
After you have retrieved a list of reports, you can deploy them. The PublishAXReport command is used to deploy the reports. The following examples show
how to use this command:

To deploy a specific report, enter the name of the report. For
example, to deploy the CustTransList report, enter the following
command: Publish-AXReport -ReportName CustTransList

To deploy two or more specific reports, enter the names of the
reports. For example, to deploy the CustTransList and
CustTransOpenPerDate reports, enter the following command:
Publish-AXReport -ReportName CustTransList,
CustTransOpenPerDate

To deploy all reports, enter the following command: PublishAXReport -ReportName *
2-5
Reporting in Microsoft Dynamics® AX 2012
Report Development Tools
Several tools are available to help you create reports, configure data sources, and
deploy and display report data in Microsoft Dynamics AX 2012. Integration
between these tools makes report development more streamlined than ever and
reduces the time that is required to create and modify reports.
MorphX and the Application Object Tree
MorphX is the integrated development environment that is included in Microsoft
Dynamics AX 2012. The programming language X++ is used within the MorphX
development environment. X++ is an object-oriented programming language that
is used to develop the objects that are used in the Microsoft Dynamics AX
application.
The Application Object Tree (AOT) holds all the application objects that are used
to build Microsoft Dynamics AX. The AOT contains objects that will be used to
collect data for a report and objects that give users access to display reports.
The objects in the AOT are grouped into nodes according to their type. The AOT
objects include:

Tables - made of fields that contain business data

Views - grouped data from multiple tables

Classes - source code for application logic

Visual Studio Projects - report definitions copied from Visual Studio

Queries - select data to display in a form or in a report

Menu items - used to access reports and forms

Menus - groups of menu items
Other objects in the AOT are used to manage application processes and for
various other functions.
When you develop a report, objects from the AOT will be used to access data and
to display the reports.
Visual Studio
Microsoft Visual Studio is an integrated development environment that is used to
develop applications. Development in Visual Studio can be done using Visual
Basic, Visual C#, Visual C++, and other programming languages. Whereas many
development tasks in Microsoft Dynamics AX 2012 can be completed by using
X++ in the MorphX development environment or the Visual Studio development
environment, report development can only be done in Visual Studio.
2-6
Chapter 2: SQL Server Reporting Services
Visual Studio consists of several features that support development of Microsoft
Dynamics AX applications. Visual Studio Tools for Microsoft Dynamics AX is a
collection of tools and functionality that allow you to manage code development
for Microsoft Dynamics AX. Visual Studio Tools integrates Microsoft Dynamics
AX with Visual Studio. Objects that are developed in Visual Studio can be saved
to the AOT and AOT objects can be used in Visual Studio development projects.
FIGURE 2.3 VISUAL STUDIO
Application Explorer is a tool in Visual Studio that provides a view into the AOT
in Microsoft Dynamics AX. In Application Explorer, you can view and debug
X++ code in the AOT.
Solution Explorer displays a collection of items for a specific solution. A solution
contains one or more projects, and a project contains one or more items. From
Solution Explorer, you can open files for editing, add new files to a project, and
view solution, project, and item properties.
2-7
Reporting in Microsoft Dynamics® AX 2012
SQL Server Reporting Services
SQL Server Reporting Services (SSRS) provides tools and services to help you
create, deploy, and manage reports. SSRS also provides programming features
that allow you to extend and customize your reporting functionality.
Reporting Services is a server-based reporting platform that provides
comprehensive reporting functionality for a variety of data sources. Reporting
Services includes a complete set of tools for you to create, manage, and deliver
reports, and provides APIs that enable developers to integrate or extend data and
report processing in custom applications. Reporting Services tools work within
the Microsoft Visual Studio environment and are fully integrated with SQL
Server tools and components.
With Reporting Services, you can create interactive, tabular, graphical, or freeform reports from relational, multidimensional, or XML-based data sources. You
can publish reports or access reports on demand. Reporting Services also enables
you to create customized reports based on predefined models, and to interactively
explore data within the model. Additionally, you can select from a variety of
viewing formats or export reports to other applications. The reports that you
create can be viewed over a web-based connection or as part of a Microsoft
Windows application or SharePoint site.
SQL Server Analysis Services
Microsoft SQL Server Analysis Services (SSAS) delivers online analytical
processing (OLAP) and data mining functionality for business intelligence
applications. Analysis Services supports OLAP by letting you design, create, and
manage multidimensional structures that contain data that is aggregated from
other data sources, such as relational databases. For data mining applications,
Analysis Services lets you design, create, and visualize data mining models that
are constructed from other data sources by using a wide variety of industrystandard data mining algorithms
Analysis Services helps you analyze large quantities of data. With it, you can
design, create, and manage cubes that contain detail and aggregated data from
multiple data sources.
For more information, see Chapter 3: SQL Server Analysis Services of this
manual.
Business Intelligence Development Studio
Business Intelligence Development Studio is Microsoft Visual Studio 2008 with
additional project types that are specific to SQL Server business intelligence.
Business Intelligence Development Studio is the primary environment that you
will use to develop business solutions that include Analysis Services and
Integration Services projects. Each project type supplies templates for creating
the objects that are required for business intelligence solutions, and provides a
variety of designers, tools, and wizards to work with the objects.
2-8
Chapter 2: SQL Server Reporting Services
Develop Reports
All reports in Microsoft Dynamics AX 2012 are developed by using Visual
Studio. Default reports that are installed with Microsoft Dynamics AX 2012 can
be customized and new reports can be created by using Visual Studio.
Create New Reports
To create a new report, you must create a report project in Visual Studio, add a
new report and report design to the project, and then define data and parameters.
The report project is then imported in to Microsoft Dynamics AX 2012 and then
the report is deployed to the Report Server. A menu item can then be created to
launch the report, or the report can be added to a Role Center or Enterprise Portal
web part.
Create a Reporting Project
To create a new report, begin by creating a new reporting project in Visual
Studio. Follow these steps to create a new reporting project:
1. In Visual Studio, select File > New > Project from the menu.
2. Select Microsoft Dynamics AX for the project template type and
then select the report model template.
3. Enter a project and solution name.
2-9
Reporting in Microsoft Dynamics® AX 2012
4. Verify the path for the location where the project file will be saved.
5. Click OK.
FIGURE 2.4 VISUAL STUDIO NEW PROJECT DIALOG BOX
To add a new report to the project, select the Project in Solution Explorer in
Visual Studio. Right-click the project and select Add > Report.
Instead of creating a new Reporting Project, you might want to use an existing,
pre-defined Reporting Project. Follow these steps to add an existing Reporting
Project from another solution:
1. Select the solution in Solution Explorer in Visual Studio. Right-click
the solution and then click Add > Existing Project.
2. Select the reporting project to add, and then click Open.
2-10
Chapter 2: SQL Server Reporting Services
When you add an existing reporting project from another solution, the project
files are not copied to the directory that contains the files for the solution.
Instead, the project files from the original solution are used.
You can also add an existing report from the AOT that is displayed in the
Application Manager in Visual Studio. Follow these steps to add an existing
report to the current project:
1. In Visual Studio, open a solution and select a project in the Solution
Explorer.
2. In Application Explorer, expand the SSRS Reports node and then
expand the Reports node. Find the report that you want to add to the
project.
3. Right-click the report and select Add to Project. The report is added
to the current project.
Define a Data Source
To add data for your reports, a data source must be added to the report project.
An existing data source is used to connect to the Microsoft Dynamics AX 2012
application database. When the predefined Microsoft Dynamics AX data source
is used, all data access requests go through the MorphX security system.
2-11
Reporting in Microsoft Dynamics® AX 2012
If you want to use a database other than the Microsoft Dynamics AX 2012
application database, you must define a new data source to specify connection
information and a provider type for that database. Follow these steps to define a
report data source:
1. In Visual Studio Solution Explorer, right-click the reporting project
that you want to add a report data source to, select Add, and then
click Report Data source. This is a model that contains a single
report data source.
2. Type a name for the model. The file name extension of a model is
.moxl.
FIGURE 2.5 ADD NEW DATA SOURCE IN VISUAL STUDIO
Define a Dataset
A report dataset selects data from the data source to be displayed in a report. You
can use a query, stored procedure, enum, or a data method to select data.
1. Double-click the report in the project in Visual Studio Solution
Explorer to open the report in the Model Editor.
2. In the Model Editor, expand the node for the report that you want to
work with.
3. Right-click the Datasets node, and then click Add Dataset.
4. Select the node for the dataset.
2-12
Chapter 2: SQL Server Reporting Services
5. In the Properties window, set the following properties.
o
o
a.
b.
c.
d.
o
o
o
Data Source - Select the Microsoft Dynamics AX data source,
or a new data source that was created.
Data Source Type - Select the type of data source that you will
use to select data. If the existing Microsoft Dynamics AX data
source is selected, you can choose from the following:
Query - use a query from the AOT
Business Logic - use a data method from the report project
Report Data Provider - use the results of an X++ class
AX Enum Provider - use an enum from the AOT
Name - Enter a name for the dataset.
Query - Select a query, method, class or enum to use to retrieve
the data from the data source.
Default Layout - default layout to be used for Auto Design
reports. Dynamic Filters - enables filters to be used in the report
dialog.
FIGURE 2.6 DATASET PROPERTIES IN VISUAL STUDIO
Define a Data Region
A data region is an area in a report that displays data from a dataset. To add a
data region to an auto design report, drag a dataset onto a report design. A data
region can also be added manually. Follow these steps to add a data region to an
auto design report:
1. In the Visual Studio Model Editor, select the dataset for the report
where you want to create a data region.
2. In the Properties window, verify the appropriate Default Layout
property is selected.
2-13
Reporting in Microsoft Dynamics® AX 2012
3. To create a new auto design, drag the dataset onto the Designs node
for the report. To add the data region to an existing auto design, drag
the dataset onto the node for the auto design. A node for the data
region is created under the Designs node.
4. Select the new data region. In the Properties window, specify a style
template.
5. Preview the report to verify the data region is correct. Right-click the
design and select Preview.
Follow these steps to manually add a data region:
1. In the Visual Studio Model Editor, select the auto design for the
report that you want to create a data region.
2. Right-click the auto design, click Add, and select a data region type.
Select from: List, Matrix, Pie or Doughnut Chart, Table, or XY
Chart.
3. Select the new data region. In the Properties window, specify a
dataset and a style template.
4. Preview the report to verify the data region is correct. Right-click the
design and select Preview.
Define a Report Filter
Filters are used to filter data that is displayed in a report. Set ranges can be
defined to filter data on a report. If the Dynamic Filter property on the dataset is
set to True, the report user will identify the ranges when he or she views the
report. If the Dynamic Filter property on the dataset is set to False, the report
developer must specify the data ranges. Use the following procedure manually
define a filter for a data region:
1. In the Visual Studio Model Editor, select the design to modify in the
Design node under the report to edit.
2. Expand the node for the auto design to view its data regions.
3. Select the Filter node under the data region. Right-click the Filters
node, and then click Add Filter.
2-14
Chapter 2: SQL Server Reporting Services
4. Select the new filter and specify the following properties:
o
o
o
o
Expression - select an expression or select <Expression...> to
open an Edit Expression dialog box
Name - enter a name for the expression
Operator - select an operator for the expression
Value - enter a value for the filter
FIGURE 2.7 REPORT FILTER PROPERTIES
Define a Sorted Data Range
To control the sort order in a report data region, define a sort order. A sort order
is set when the report is built. For example, you might want to display customer
data alphabetically by last name or numerically by account number. To sort data
in a data region:
1. In the Visual Studio Model Editor, select the data region in the
design node for the report to sort.
2. To define a sort order outside a grouping, right-click the Sorting
node, and then click Add Sort. To define a sort order within a
grouping expand the node for the grouping, right-click the Sorting
node, and then click Add Sort.
2-15
Reporting in Microsoft Dynamics® AX 2012
3. Select the new sort order.
4. In the Properties window, specify the following properties:
o
o
o
Name - name for the sort
Sort By - select an expression or select <Expression...> to open
an Edit Expression dialog box
Sort Order - select Ascending or Descending
FIGURE 2.8 REPORT SORT ORDER PROPERTIES
Display Images in a Report
Several scenarios are available that allow you to display images in a report. Some
reports can include a specific image for each record in the report, whereas others
might include a few standard images that are used each time the report is used.
The following are ways to reference an image in a report:
2-16

Embedded - the image is added directly to the reporting project

External - the image is store outside the project, referenced by a URL

Database - the image is stored with a record in the database
Chapter 2: SQL Server Reporting Services
External images can only be used for Precision Reports. Precision Reports are
developed using SQL Report Designer to allow for precise layouts, such as for
invoices or checks.
The following procedure shows how to add an embedded image:
1. To add an image and make it available to all reports in the model,
select Image from the Add Element drop-down menu on the toolbar
of the Visual Studio Model Editor.
2. To add the image directly to a report, right-click the desired report,
click Add, and then click Image. When you add an image directly to
a report, it is available to that report only.
3. Select the new image node. In the Properties window select the
image file in the Image Source field. Valid file types for image files
are: .bmp, .gif, .jpeg, .png, and .xpng.
Build a Reporting Project
After the report is developed, the reporting project needs to be built. When you
build a reporting project, the report is updated in the model store. Projects with
business logic will build the assembly and add it to the output path for the
project. You can build a solution or a project. When you build a solution, all
projects in the solution are built. When you build a project, the project and any
nested projects are built.
To build a solution by using Microsoft Visual Studio, in Solution Explorer, rightclick the solution, and then click Build Solution.
To build a project using Microsoft Visual Studio, in Solution Explorer, rightclick the project, and then click Build.
Edit Existing Reports
When a specific report is being developed, there is often an existing report that
will meet many of the report requirements. The existing report can be modified to
add fields, change parameters or change the report layout.
When reports in Microsoft Dynamics AX 2012 are modified, changes are stored
in the development layer in the MorphX development environment that the
developer is logged into. A copy of the reporting project is created and opened in
Microsoft Visual Studio where it can be edited and then imported back into the
AOT in the layer that the developer is currently working in. Before making
changes to a report, make sure that you are working in the correct development
layer.
2-17
Reporting in Microsoft Dynamics® AX 2012
Follow these steps to edit an existing report:
1. In the AOT, open Visual Studio Projects and then open Microsoft
Dynamics AX Model Projects.
2. Find the project that contains the report to edit, right-click the project
and then click Edit. This opens the project in Visual Studio.
3. In the project in Visual Studio, use the Solution Explorer to find the
report to edit. Double-click the report to open the report in Model
Editor.
4. Use the Model Editor to make changes to the report data, parameters
or design.
FIGURE 2.9 VISUAL STUDIO MODEL EDITOR
5. To preview the report changes, expand the Designs node for the
report.
6. Right-click the design that you want to preview, and then click
Preview.
After the report is modified in Visual Studio, the report project can be imported
back into Microsoft Dynamics AX 2012. Follow the procedure that is described
in the "Integrate SSRS with Microsoft Dynamics AX 2012" lesson of this manual
to import a Report Project into Microsoft Dynamics AX 2012.
2-18
Chapter 2: SQL Server Reporting Services
Deploy Reports
After a report is developed in Visual Studio, it must be deployed to the SQL
Reporting Server to be used. Reports can be deployed from Visual Studio, from
the AOT, or by using Windows PowerShell. When a report is deployed, the
following occurs:

The Report Definition Language (RDL) is uploaded to Reporting
Services.

The business logic assemblies are copied to the Reporting Services
server.

Any reports and business logic assemblies that are referenced in the
report are verified.
Deploy Reports with Visual Studio
If a new report is developed in Visual Studio, the report can be deployed directly
from Visual Studio. In the Visual Studio Solution Explorer, right-click the
reporting project that contains the reports that you want to deploy and then click
Deploy. Reports are deployed for the neutral language only.
Deploy Reports with Microsoft Dynamics AX 2012
Development Workspace
Existing reports in Microsoft Dynamics AX 2012 can be re-deployed if needed.
If changes are made to a report, or new reports are developed and imported into
Microsoft Dynamics AX 2012, they will need to be deployed before they can be
used. The following procedure outlines how to deploy reports from Microsoft
Dynamics AX 2012:
1. Press SHIFT+CTRL+W to open the development workspace.
2. In the AOT, expand the SSRS Reports node.
2-19
Reporting in Microsoft Dynamics® AX 2012
3. Expand the Reports node.
4. Right-click the report that you want to deploy, and then click Deploy
Element.
FIGURE 2.10 DEPLOY REPORTS FROM AOT
Deploy Reports with Windows PowerShell
To deploy reports using Windows PowerShell, follow the procedure listed in the
"Installation" lesson of this manual.
Integrate SSRS with Microsoft Dynamics AX 2012
After reports are created in Visual Studio 2010 and deployed to SSRS, users must
be able to view them. An advantage of reports that are built in Visual Studio is
that they are very flexible in the formats in which they can be rendered. While
paper reports are still necessary for some occasions, publishing reports digitally,
or making reports available for subscription, is becoming a widely popular
alternative.
2-20
Chapter 2: SQL Server Reporting Services
Import a Report Project to Microsoft Dynamics AX 2012
Before a new report can used in Microsoft Dynamics AX 2012, it must be
imported from Visual Studio. To import report projects to Microsoft Dynamics
AX 2012, right-click the reporting project in the Visual Studio Solution Explorer,
and then click Add Report to AOT.
Create a Menu Item
After the report is imported to Microsoft Dynamics AX 2012, a menu item can
be created to provide access to the reports. An output menu item is created from
the Menu Items node in the AOT and references the imported report. Follow
these steps to create a menu item for a report:
1. In the AOT, expand the Menu Items node.
2. Right-click the Output node, and click New Menu Item.
3. Select the new menu item.
4. In the Properties window enter a name of the report menu item, enter
a label for the report title, set the ObjectType property to
SQLReportLibraryReport, and then select the report from the drop-down
menu for the Object property.
FIGURE 2.11 MICROSOFT DYNAMICS AX 2012 AOT MENU ITEM
PROPERTIES
2-21
Reporting in Microsoft Dynamics® AX 2012
Add a Report to a Role Center Page
The Microsoft Dynamics AX report web part is used to display reports in Role
Centers and the Enterprise Portal. There are two options for Role Center
modifications: a user-specific personalization, called the Personal Version, or a
modification by the administrator, called the Shared Version, that can be viewed
by all users with that role center profile.
When the Role Center is displayed as the Home page in the Microsoft Dynamics
AX client, the user can make personal modifications to the role center for their
own use only. To do that, the user clicks "Personalize this page". This displays
the SharePoint personal version of the page. In the Infolog Web Part, a message
informs the user that "You are editing the Personal Version of this page". The
user can click "Add a Web Part" to add a new report web part to any region of
the page.
When the Role Center is displayed in the Enterprise Portal, an administrator can
click "Site Actions" and select "Edit Page". This displays the SharePoint shared
version of the page. The Administrator can click "Add a Web Part" to add a new
report web part to any region of the page.
In both cases, there is a region displayed that is labeled "Categories" that contains
a link to the "Microsoft Dynamics AX" web parts. When that link is selected, the
adjacent "Web Parts" region, displays all the options available. Use the right
arrow to scroll down through the list to find the Report web part. In the "About
the Web Part" region, the drop-down list labeled "Add Web Part to:" allows the
user to select the region of the page. Click the Add button.
The following step show how to choose the specific report to display for the web
part:
1. Under the label "Microsoft Dynamics AX report" a message is
displayed providing an instruction. Click on the unlabeled down
arrow in the upper-right above the message. Choose "Edit Web Part"
if you are editing the Shared View. Choose "Edit My Web Part" if
you are editing a Personal View. This displays the properties pane as
a vertical pane in the rightmost part of the SharePoint page.
2. In the properties of the web part, choose the desired report from the
list displayed under "Select a report".
3. If the SSRS report uses parameters, you can see what parameter
values can be set for the report under the "Report parameters" section
of the properties.
4. Under the Report toolbar section of the properties, you can specify
the Toolbar Size property to indicate whether a toolbar should be
displayed for the web part.
5. Under the "Appearance" section of the properties, enter an
appropriate title for the report. This title will be displayed in the
Microsoft Dynamics AX Report Server Report web part.
6. Set the Width and Height properties to the desired values.
2-22
Chapter 2: SQL Server Reporting Services
Batch Integration
Reports can be printed using a batch job to print on a recurring schedule, or to
print during off hours.
To print a specific report on a recurring basis:
1. Click the menu item for the report that you want to print.
2. Enter parameters in the print dialog form.
3. Click the Destinations button to display the Print destination
settings form.
4. Select a print destination.
5. Click the Batch tab.
6. Select the Batch processing check box.
7. Enter a task description.
8. Select the batch group that this batch job will be a part of.
9. Click Recurrence to display the Recurrence form. Specify how
often you want the report to be printed. Then click OK to close the
Recurrence form.
10. Click Alerts. Specify how and when you want to receive alerts for
the batch job. Click OK to close the form.
11. Click OK to print the report to the selected destination on a recurring
basis.
FIGURE 2.12 MICROSOFT DYNAMICS AX 2012 REPORT BATCH SETUP
2-23
Reporting in Microsoft Dynamics® AX 2012
Lab 2.1 - Create a Simple Report
This lab will focus on how to develop a simple report. Topics include using free
text and query bound report parameters, sorting and filtering report data, and
applying report templates to produce uniform views of Microsoft Dynamics AX
data.
Scenario
Isaac, the Developer, wants to create an SSRS report to expose customer
transaction data.
Challenge Yourself!
Use the provided information to create a query bound report that exposes
Customer Transaction data.
Need a Little Help?
1.
2.
3.
4.
5.
6.
7.
8.
Create a Microsoft Dynamics AX Query
Add field data to the Query.
Create a new report model in Visual Studio.
Create a report data set.
Create a report design.
Apply Style Templates.
Save and deploy the report.
View the report in Microsoft Dynamics AX 2012.
Step by Step: Create an AX Query
1.
2.
3.
4.
5.
6.
7.
8.
9.
2-24
Open Microsoft Dynamics AX.
Press Ctrl+Shift+W to enter the development environment.
In the AOT, right-click the Queries node, and then click New Query.
Right-click the node for the query, click Rename, and then type
"CustTrans_W1".
Expand the CustTrans_W1 node.
Right-click the Data Dictionary node, and then click Open New
Window.
In the new window, expand the Tables node.
Locate the CustTrans table and drag it onto the Data Sources node
for the CustTrans_W1 query.
Expand the CustTrans_1 Data Source node.
Chapter 2: SQL Server Reporting Services
10. Select and drag the following fields from the Fields node under
CustTrans table to the Field node under CustTrans_1 data source:
o AccountNum
o AmountMST
o TransDate
o TransType
o Txt
11. Right-click the Fields node of the query, click Properties.
12. Set the Dynamic property to No so fields can be removed from the
view.
13. Save the query.
FIGURE 2.13 MICROSOFT DYNAMICS AX 2012 DATASET FIELDS
2-25
Reporting in Microsoft Dynamics® AX 2012
Step by Step: Create a New Report in Visual Studio
1. Open Microsoft Visual Studio.
2. If Visual Studio is run for the first time, select General
Development Settings for the default environment setting and click
Start Visual Studio.
3. On the File menu, point to New, and then click Project. The New
Project dialog box is displayed.
4. In the Installed Templates pane, click the Microsoft Dynamics AX
node, and in the Templates pane, click Report Model.
5. In the Name box type SSRSDemo, and in the Location box, type a
file path.
6. Click OK.
7. In Solution Explorer, select the SSRSDemo project, right-click,
select Add and click Report.
8. An empty report model named Report1 is created.
9. In Model Editor, right-click the Report1 node and then click
Rename.
10. Type "CustTransList_WS1" as the name.
11. Expand the CustTransList_WS1 node if it is not already expanded.
12. Right-click the Datasets node and then click Add Dataset.
13. Select the node for the dataset.
2-26
Chapter 2: SQL Server Reporting Services
14. In the Properties window, specify the following properties.
o
o
o
o
Data Source: Dynamics AX
Data Source Type: Query
Name: CustTransListDS
Query: Select * from CustTrans_W1 (or use the ellipsis button
to use the wizard to select the query and choose the desired fields
to display).
FIGURE 2.14 VISUAL STUDIO DATASET PROPERTIES
15. In Model Editor, select the CustTransListDS node and drag it onto
the Designs node. An auto design named AutoDesign1 is created for
the report.
2-27
Reporting in Microsoft Dynamics® AX 2012
Step by Step: Apply Layout Template
1. In Model Editor, select the AutoDesign1 node.
2. In the Properties window, set the Layout Template property to
"ReportLayoutStyleTemplate". Also, type "Customer Transaction
List" for the Title property.
3. In Model Editor, expand the AutoDesign1 node, and then select the
node for the CustTransListDSTable.
4. In the Properties window, set the Style Template property to
TableStyleTemplate.
Step by Step: Add Column Sorting
1. In Model Editor, expand the AutoDesign1 node, and then select the
Sorting node under the CustTransListTable 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. Save the report.
6. In Model Editor, expand the AutoDesign1 node, and then select the
AccountNum field under the Data node.
7. In the Properties window, set the Interactive sorting property to
"True". Repeat this step for the AmountMST, TransDate, and
TransType1 columns.
8. Save the report.
Step by Step: Group Report Data
1. In Model Editor, expand the AutoDesign1 node.
2. Right-click the Groupings node under the CustTransListTable data
region, and then click Add Grouping.
2-28
Chapter 2: SQL Server Reporting Services
3. Type Group1 as the name.
4. In the Properties window, set the Label property to
"=Fields!AccountNum.Value".
FIGURE 2.15 VISUAL STUDIO GROUP PROPERTIES
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. In Model Editor, expand the AutoDesign1 node, and then select the
AccountNum field under the Data region.
9. Right-click the Group1 node and then click Properties.
10. In the Properties window, expand the Instance Aggregates, and set
Render Location to "GroupFooter".
11. Select the AmountMST field under the Data node.
12. In the Properties window, expand the Aggregation item, and set
Aggregate Function to "Sum".
2-29
Reporting in Microsoft Dynamics® AX 2012
Step by Step: Filter Report Data
1. Open Microsoft Dynamics AX.
2. In the AOT, expand the Queries node, and then locate the
CustTrans_W1 query.
3. Expand the CustTrans_W1 node and expand the Data Sources node.
4. Right-click the Ranges node and then click New Range. A default
range using the AccountNum field is created for you by AX.
5. Save the query.
6. In Visual Studio Model Editor, select the CustTransListDS node.
7. Right-click the node and select Refresh to reflect changes that you
make to the AX Query.
8. Expand the Parameters node for the report (that is not the Parameters
node for the dataset) to display the list of report parameters.
9. Right-click the node and select Add > Parameter.
10. Type "AccountParam" as the name.
11. In the Properties window, enter Account for the Prompt String
property.
12. Save the report.
13. In Model Editor, expand the nodes of AutoDesign1 to see the Filters
node.
14. Right-click the Filters node and select Add Filter.
15. Type "AccountFilter" as the name.
16. Set the following properties in the Properties window
a. Expression: =FieldsAccountNum.Value
b. Operator: Like
c. Value: =Parameters!AccountParam.Value
17. Save the report.
Step by Step: Add a Dynamic Parameter
1.
2.
3.
4.
5.
6.
Open Microsoft Dynamics AX.
Press Ctrl+Shift+W to enter the development environment.
In the AOT, right-click the Queries node and then click 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. Locate the AccountNum field under CustTable and drag to the
Fields node under the CustTrans_W1 Data Source node.
8. Save the query.
2-30
Chapter 2: SQL Server Reporting Services
9. In Model Editor, right-click the Datasets node, and then click Add
Dataset.
10. Type "CustomersDS" as the name.
11. Select the node for the dataset.
12. In the Properties window, set the following properties.
o Data Source: Dynamics AX
o Data Source Type: Query
o Default Layout: Table
o Name: CustomersDS
o Query: Select * from CustTable_W1
13.
14.
15.
16.
17.
In 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 From Dataset option button and set the following properties:
o Dataset: CustomersDS
o Value Field: AccountNum
o Label Field: AccountNum
18. Click OK.
19. Save the report.
Step by Step: Save and Deploy the Report
1. Right-click the SSRSDemo project in Solution Explorer, and select
Rebuild.
2. Verify that you have no build errors.
3. Right-click the SSRSDemo project in Solution Explorer, and select
Add SSRSDemo to AOT.
4. Verify that you can add to the AOT.
5. Right-click the SSRSDemo project in Solution Explorer, and select
Deploy.
6. Navigate to the Report Manager to view the report.
2-31
Reporting in Microsoft Dynamics® AX 2012
Step by Step: View the Report in Microsoft Dynamics AX
1. Open Microsoft Dynamics AX.
2. In the AOT, expand the Menu Items node and select the Output
node.
3. Right-click the Output node and then click New Menu Item.
4. Type "CustTransList_WS1" as the name.
5. Right-click the CustTransList_WS1 and select Properties set the
following:
o Object Type: SSRSReport
o Object: CustTransList_WS1
o Label Field: AutoDesign1
6. Save the AX Menu Item.
7. Right-click the CustTransList_WS1 menu item and select Open.
2-32
Chapter 2: SQL Server Reporting Services
Lab 2.2: Create a Report with X++ Business Logic
In this lab you will use a report data provider (RDP) class with business logic to
process data and then display the outcome of the business logic on a report. An
RDP class is an X++ class that is used to access and process data for a Reporting
Services report.
Scenario
Develop a report to display customer data with parameters for account number,
account statement and whether to include tax.
Challenge Yourself!
Use the information that is provided in the scenario to develop the report.
Need a Little Help?
1.
2.
3.
4.
5.
6.
7.
Create a temporary table
Define a report data provider class
Define the report parameters
Define a method to return data to Reporting Services
Add business logic for the report
Create a reporting project
Bind a report to a report data provider class
Step by Step: Create a Temporary Table
1. Open Microsoft Dynamics AX.
2. Press Ctrl+Shift+W to enter the development environment.
3. In the AOT, expand the Data Dictionary node, right-click the Tables
node, and then click New Table.
4. Right-click the table and click Properties.
5. In the Properties window, set the Name property to
TmpCustTableSample and set the Table Type property to TempDB.
This will define the table as a SQL Server temporary table.
6. Expand the node next to the TmpCustTableSample table so that you
can see the Fields node.
7. Press Ctrl+D to open another AOT window and move the window so
that you can see both AOT windows.
2-33
Reporting in Microsoft Dynamics® AX 2012
8. In the second AOT, expand the Data Dictionary node, expand the
Extended Data Types node, and drag the following types to the
Fields node in the first AOT window:
o AccountNum
o CustName
o LogisticsAddressing
o CustGroupID
o Phone
o CustInvoiceAccount
o Action Days
o InclTax
9. In the second AOT window, expand the Base Enums node and drag
the CustAccountStatement enumeration to the Fields node of the first
AOT window.
Step by Step: Define a Report Provider Class
1. In the AOT, right-click the Classes node, and then click New Class.
2. Right-click the new class, click Rename, and then enter
"SrsRDPSampleClass".
3. Expand SrsRDPSampleClass, right-click classDeclaration, and then
click View Code.
4. In the code editor, edit the class so that it contains the following
code.
[
SRSReportQueryAttribute (querystr(Cust)),
SRSReportParameterAttribute(classstr(SrsRDPContractSample))
]
public class SrsRdpSampleClass extends
SRSReportDataProviderBase
{
TmpCustTableSample tmpCust;
}
5. Save the class and close the editor.
Step by Step: Define a Data Contract Class
1. In the AOT, right-click the Classes node, and then select New Class.
2. Right-click the new class, click Rename, and then enter
"SrsRDPContractSample".
3. Expand SrsRDPContractSample, right-click classDeclaration, and
then click View Code.
2-34
Chapter 2: SQL Server Reporting Services
4. In code editor, enter the following code in the class declaration to
define the class.
[DataContractAttribute]
public class SrsRDPContractSample
{
AccountNum accountNum;
CustAccountStatement accountStmt;
Boolean inclTax;
}
5. Save the class and close the editor.
Step by Step: Define a Data Contract Method
1. Right-click SrsRDPContractSample, point to New, and then click
Method.
2. Edit the method so that it contains the following code.
[DataMemberAttribute("AccountNum")]
public AccountNum parmAccountNum(AccountNum _accountNum
= accountNum)
{
accountNum = _accountNum;
return accountNum;
}
3. Save the method and close the editor.
4. Right-click SrsRDPContractSample, point to New, and then click
Method.
5. Edit the method so that it contains the following code.
[DataMemberAttribute("CustAccountStatement")]
public CustAccountStatement
parmAccountStmt(CustAccountStatement _accountStmt =
accountStmt)
{
accountStmt = _accountStmt;
return accountStmt;
}
6. Save the method and close the editor.
7. Right-click SrsRDPContractSample, point to New, and then click
Method.
2-35
Reporting in Microsoft Dynamics® AX 2012
8. Edit the method so that it contains the following code.
[DataMemberAttribute("InclTax")]
public boolean parmInclTax(boolean _inclTax = inclTax)
{
inclTax = _inclTax;
return inclTax;
}
9. Save the method and close the editor.
Step by Step: Define a Method to Return the Data to
Reporting Services
1. Right-click SrsRdpSampleClass, point to New, and then click
Method.
2. Edit the method so that it contains the following code.
[SRSReportDataSetAttribute("TmpCust")]
public TmpCustTableSample getTmpCustTable()
{
select * from tmpCust;
return tmpCust;
}
3. Save the method and close the editor.
Step by Step: Add Business Logic for the Report
1. Right-click SrsRdpSampleClass, point to Override method, and
then click processReport.
2. Edit the method so that it contains the following code.
public void processReport()
{ AccountNum accountNumber;
CustAccountStatement custAcctStmt;
boolean boolInclTax;
Query query;
QueryRun queryRun;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
CustTable queryCustTable;
SrsRdpContractSample dataContract; // Get the query from the runtime using a
dynamic query.
// This base class method reads the query specified in the SSRS
ReportQueryAttribute attribute.
query = this.parmQuery(); // Get the parameters passed from runtime.
// The base class methods read the SRSReportParameterAttribute attribute.
dataContract = this.parmDataContract();
accountNumber = dataContract.parmAccountNum();
custAcctStmt = dataContract.parmAccountStmt();
2-36
Chapter 2: SQL Server Reporting Services
boolInclTax = dataContract.parmInclTax(); // Add parameters to the query.
queryBuildDataSource =
query.dataSourceTable(tablenum(CustTable)); if(accountNumber)
{
queryBuildRange =
queryBuildDataSource.findRange(fieldnum(CustTable, AccountNum)); if
(!queryBuildRange)
{
queryBuildRange =
queryBuildDataSource.addRange(fieldnum(CustTable, AccountNum));
} // If an account number has not been set, then use the parameter value to set it.
if(!queryBuildRange.value())
queryBuildRange.value(accountNumber); } if(custAcctStmt)
{ queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable,
AccountStatement));
if (!queryBuildRange)
{
queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable,
AccountStatement));
} // If an account statement has not been set, then use the parameter value to set
it.
if(!queryBuildRange.value())
queryBuildRange.value(int2str(custAcctStmt)); } if(boolInclTax)
{ queryBuildRange =
queryBuildDataSource.findRange(fieldnum(CustTable, InclTax)); if
(!queryBuildRange)
{
queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable,
InclTax));
} // If flag to include tax has not been set, then use the parameter value to set it.
if(!queryBuildRange.value())
queryBuildRange.value(int2str(boolInclTax)); } // Run the query with modified
ranges.
queryRun = new QueryRun(query); ttsbegin;
while(queryRun.next())
{ tmpCust.clear();
queryCustTable = queryRun.get(tablenum(CustTable));
tmpCust.AccountNum = queryCustTable.AccountNum;
tmpCust.CustName = queryCustTable.name();
tmpCust.LogisticsAddressing = queryCustTable.address();
tmpCust.CustGroupId = queryCustTable.CustGroup;
tmpCust.Phone = queryCustTable.phone();
tmpCust.CustInvoiceAccount = queryCustTable.InvoiceAccount;
tmpCust.CustAccountStatement = queryCustTable.AccountStatement;
tmpCust.InclTax = queryCustTable.InclTax;
tmpCust.insert(); }
ttscommit; }
3. Save the method and close the editor.
2-37
Reporting in Microsoft Dynamics® AX 2012
Step by Step: Create a Reporting Project
1. Open Microsoft Visual Studio.
2. On the File menu, point to New, and then click Project. The New
Project dialog box is displayed.
3. In the Installed Templates pane, click Microsoft Dynamics AX. In
the Templates pane, click Report Model.
4. In the Name box, type SampleRDPReport, and in the Location box,
type a location.
5. Click OK.
Step by Step: Bind a Report to a Report Data Provider
Class
1. In Solution Explorer, right-click the SampleRDPReport node, point
to Add and then click Report.
2. In Model Editor, right-click the Report1 node, and then click
Rename.
3. Type "CustomerReport" as the name.
4. Right-click the Datasets node, and then click Add Dataset.
5. In the Properties window, specify the following values.
o Data Source: Dynamics AX
o Data Source Type: Report Data Provider
o Default Layout: Table
o Name: Customer
o Dynamic Filters: True
This setting is for dynamic parameters on the report. Setting the property to True
allows you to filter the report by setting a range on any fields from the data
source table.
6. For the Query property, click the ellipsis button (…). A dialog box
displays where you can select an RDP class that is defined in the
AOT and identify the fields that you want to use. Select the
SrsRDPSampleClass class and click Next. In the Select Fields
dialog box, keep all the check boxes selected, and then click OK.
7. In Model Editor, select the Customer node and drag it onto the
Designs node. An auto design named AutoDesign1 is created for the
report. Based on what you select, the Query property value is
updated. In this case, the query is SELECT * FROM
SrsRDPSampleClass.TmpCust.
2-38
Chapter 2: SQL Server Reporting Services
Summary
Reports in Microsoft Dynamics AX 2012 are developed using SQL Server
Reporting Services and Visual Studio instead of X++. The move to SSRS puts
Microsoft Dynamics AX reports on Microsoft's preferred reporting platform
providing users professional-looking reports, more export formats, and a more
capable report designer.
2-39
Reporting in Microsoft Dynamics® AX 2012
Test Your Knowledge
1. True or False. Reports are not fully-integrated into the Microsoft Dynamics
AX security system.
( ) True
( ) False
2. What tool can be used to deploy Microsoft Dynamics AX 2012 reports?
(Select all that apply)
( ) Windows PowerShell
( ) Microsoft Dynamics AX 2012 Installation
( ) Microsoft SQL Server Reporting Services
( ) Microsoft Visual Studio
3. True or False. The new Report Data Provider classes let you build reports
that use data from an X++ class as the source.
( ) True
( ) False
4. What are some advantages of the new SSRS reporting architecture over X++
reports? (Select all that apply)
( ) Professional-looking reports
( ) More flexible architecture
( ) More supported export formats
( ) Better report designer
5. What are some options for upgrading existing Microsoft Dynamics AX 2009
SQL Server Reporting Services (SSRS) reports?
( ) Rewrite the SSRS report using the X++ reporting framework
( ) Do not upgrade the reports. Use a SQL Server Reporting Services
template and customize it to meet your needs.
( ) Deploy the SSRS report using the deployment wizard.
( ) Use the Report Upgrade Tool to upgrade the reports so that they are
compatible with the Microsoft Dynamics AX 2012 schema.
2-40
Chapter 2: SQL Server Reporting Services
Quick Interaction: Lessons Learned
Take a moment and write down three key points you have learned from this
chapter
1.
2.
3.
2-41
Reporting in Microsoft Dynamics® AX 2012
Solutions
Test Your Knowledge
1. True or False. Reports are not fully-integrated into the Microsoft Dynamics
AX security system.
( ) True
() False
2. What tool can be used to deploy Microsoft Dynamics AX 2012 reports?
(Select all that apply)
() Windows PowerShell
() Microsoft Dynamics AX 2012 Installation
( ) Microsoft SQL Server Reporting Services
() Microsoft Visual Studio
3. True or False. The new Report Data Provider classes let you build reports
that use data from an X++ class as the source.
() True
( ) False
4. What are some advantages of the new SSRS reporting architecture over X++
reports? (Select all that apply)
() Professional-looking reports
() More flexible architecture
() More supported export formats
() Better report designer
5. What are some options for upgrading existing Microsoft Dynamics AX 2009
SQL Server Reporting Services (SSRS) reports?
( ) Rewrite the SSRS report using the X++ reporting framework
() Do not upgrade the reports. Use a SQL Server Reporting Services
template and customize it to meet your needs.
( ) Deploy the SSRS report using the deployment wizard.
( ) Use the Report Upgrade Tool to upgrade the reports so that they are
compatible with the Microsoft Dynamics AX 2012 schema.
2-42
Download