Reports and Data Methods

In this post, I will explain how to use data methods in Reports. We will use the same Report model and report that we created in Building a Simple Report–Precision Design.

In AX 2009, AX SSRS had good use of these data methods. But with much better integration, and Reporting framework in AX improving, Data Methods in AX SSRS are reduced to minimal use.

Also the reason is that MS is soon going to do away with .Net Business Connector from next version hence the usage of data methods for many things will be redundant. What I have also noticed is the data methods have return type only as System.String and you will not be able to change this return type. This means, data methods can only return strings.

What I will try and demonstrate here is how to add links in AX reports (to open the corresponding forms).

To achieve this first we will add the reference to SRSDrillThroughCommon project. Do the following:

  • Open the SKL_SampleReportProject (refer to link above)
  • In Application Explorer, right-click Visual Studio Projects > C Sharp Projects > SRSDrillThroughCommon and then click Edit. This adds the SRSDrillThroughCommon project to our current solution

image

  • Open the report SKL_SampleReportPrecision project
  • Right click on the Data Methods node and create a new DataMethod. Name it CustDrillDown
  • You will also notice that a Business Logic Project is automatically added

image

  • In Solution Explorer, right-click the business logic project and then click Add Reference

image

  • Go to “Projects” tab and select “SRSDrillThroughCommon” and click Ok

image

  • Double click the data method this opens the Code editor
  • Add this line of code the declaration

using Microsoft.Dynamics.AX.Application.Reports;

 

  • Your code editor should be like this

using System;

using System.Collections.Generic;

using System.Security.Permissions;

using System.Data;

using Microsoft.Dynamics.Framework.Reports;

using Microsoft.Dynamics.AX.Application.Reports;

 

public partial class SKL_SampleReportPrecision

{

    [DataMethod(), PermissionSet(SecurityAction.Assert, Name = “FullTrust”)]

    public static string CustDrillDown(string reportContext, string custAccount)

    {

        return DrillThroughCommonHelper.ToCustomerForm(reportContext, custAccount);

    }

}

  • Right click on Precision Design and open the designer
  • Select the AccountNum text box, underline the text and set font color to Blue

image

  • Now right click on this text box and select “Text Box Properties…”, Switch to Tab “Action”
  • Select option “Go to URL” and click button “fx

image

  • Set Expression “=CustDrillDown(Parameters!AX_ReportContext.Value, Fields!AccountNum.Value)”
  • Click Ok
  • Save report, go to AX, deploy the report and run it. You should see following

image

  • Click on the link and the customer form opens up

image

Building a Simple Report–Precision Design

In this post, we will see how we can build a report using precision design. A precision design is like a pre-printed format where the placing of report controls, the design and the spacing matters a lot.

A precision design is the standard SSRS report designer following the same principles, rules and requirements as are found in a SQL Server Business Intelligence Studio SSRS designer.

We will again use the same example of printing Customer Id, Customer name and Balance but this time instead of creating an Auto Design we will use Precision Design.

I will also show how we can use some inbuilt parameters to display some generic information like page number, execution date and time etc.

Here we will use the same AOT query created in previous example Build and Deploy Simple Report–Queries: SKL_SampleCustomer

Create the Required Dataset

  • Open the previously created Report Model

image_thumb26

  • Right click on report model, select Add –> Report. Name the report SKL_SampleReportPrecision
  • Set the report title to “Customer balance”

image

  • Now in the report, go to the Datasets section and create new Dataset using the name Customer
  • In the query property, click the button image_thumb6
  • This opens up the query selection box to select a Microsoft Dynamics AX Query
  • From the list select “SKL_SampleCustomer” and click Next
  • image_thumb20

  • Here you can select required fields. Either you can select all fields or a subset
  • Expand All Fields nodes under the CustTable node to select “AccountNum”
  • Expand Node “All Display Methods” and select “name” and “openBalanceMST”
  • Click “Ok”
  • Now Right click on the designs node, select Add and then “Precision Design”. This creates a new Precision Design and name it as PrecisionReport

image

  • Now right click on new Design and select “Edit Using Designer”

image

  • This opens up the SSRS Designer (same as standard SSRS)
  • You can see the standard Report Item tool bar from where you can drag and drop the controls onto the designer surface

image

  • Now from the controls tool bar, drag and drop the Table control onto the Report Designer
  • Select the Tablix and then set the DataSetName property = “Customer”

image

  • Now let us specify headers, Select one text box in the header section and right click, then select “Expression…”

image

  • In the expression editor, you can see lot of sections for Variables, Parameters, Fields, Datasets etc.
  • Here write the following in the space “Set expression for: Value” –  =Labels!@SYS316441
  • This displays the header text using the labels in AX. This label is “Customer”

image

  • Now again specify the values in Second and third text boxes in header row
  • 2nd Column Header(Name) : =Labels!@SYS117778
  • 3rd Column Header (Amount): =Labels!@SYS62867

Specifying the data for the table

  • Now in the data row, move the mouse to first text box and you should see a button on the right side that looks as shown below

image

  • Click the button and it displays the list of fields from the dataset, select required fields

image

  • Alternatively, you can right and use “Expression…” box to specify the data fields. The expression box looks as shown below:

image

Now that the data is ready, we will go ahead and change the look and feel of the report

Formatting the table

You can specify the lots of formats using the properties windows like Background color, Font type color etc. You can also use the formatting tool bar above to format the data

image

Go ahead and specify the borders for the table for each row. Then change the background of the Header row. Make the text in the header row as center aligned and make the font as bold

Select the table rows one by one and change the font to “Segoe UI” and Font Size to “8pt”. Now your table looks as shown below:

image

Now we will go ahead and a Page Header and Page Footer. In Page Header, we will add Report name, Report Title and Execution Date and Time. In the Page Footer, we will add the Page Numbers in the format (Page of Total Pages)

To enable Page Header and Footer, in the Report menu select “Add Page Header” and “Add Page Footer” options

image

image

Now drag three text boxes from tool box and drop onto the Page Header area. Place two text boxes on the left hand corner and one on the right hand corner as shown below. Drag and drop one text box in the center of the Page footer as shown below.

image

Select the first text box, Open the expression box and in the Category section, select “Built-in Fields. Now double click on “ReportName” field and it should add the report name to value section

image

In the same way select “ExecutionTime” in third text box. For report title, Type in “Customer balances” in the second text box

In the footer section, select the 4th text box and type the expression ‘=Globals!PageNumber & ” of ” & Globals!TotalPages’

Apply formatting as required. Now you should see the design as follows

image

Now close the designer, add the report back to AOT (along with the model) and deploy the report from within AOT.

Create a new menu item

Go to AOT –> Menu Items –> Output, Right click and select “New Menu Item”. Set following properties

image

Now run the report and the report will be seen as shown below:

image

Building a simple report – Using Report Data Provider

In my previous post, I explained how we can build a simple report using just the AOT queries. Now what if we have some logic that needs to be implemented and cannot be achieved using AOT queries?

This is where Report Data Providers plays a significant roles. Let us take the same example of displaying the Customer Id, Name and Balance that was used in post “Build and Deploy Simple Report–Queries”.

We can have this report using Report Data Providers as well. For this, we will keep the query and create three more artifacts, RDP, Report and a new Output menu item.

First we create a Report Data Provider class named “SKL_SampleReportDP”. Do the following:

To create an RDP for a report, we also need a temporary table (if it is Base Provider) or a permanent table (if it is pre process provider).

For this sample, we will use CustTmpAccountSum table that is present in base product.

Here are the class methods

/// <summary>

/// The <c>SKL_SampleReportDP</c> class is the report data provider class for the

/// SKL_SampleSimpleReportQuery report.

/// </summary>

/// <remarks>

/// This is a sample class. Author: Sumit Loya

/// </remarks>

[ SRSReportQueryAttribute (querystr(SKL_SampleCustomer))]

class SKL_SampleReportDP extends SRSReportDataProviderBase

{

    CustTmpAccountSum   tmpAccountSum;

}

 

The class declaration contains one attribute “SRSReportQueryAttribute”. This attribute specifies the query that will be used for this report. In case no query is required, this attribute can be removed.

There is one other attribute that can be specified on the RDP class and that is SRSReportParameterAttribute. This attribute defines the contract class that will be used to display report parameters.

processReport method

The processReport method is the entry point for calculating the report data for dataset. Here is the method for our sample class

[SysEntryPointAttribute(false)]

public void processReport()

{

    this.insertTmpAccountSum();

}

 

insertTmpAccountSum method

This is a private method that uses the report query to insert data into the temporary table

/// <summary>

/// This method processes the report query and inserts data into the CustTmpAccountSum temporary table

/// </summary>

private void insertTmpAccountSum()

{

    QueryRun            queryRun = new QueryRun(this.parmQuery());

    CustTable           custTable;

   

    while (queryRun.next())

    {

        custTable = queryRun.get(tableNum(custTable));

       

        tmpAccountSum.AccountNum    = custTable.AccountNum;

        tmpAccountSum.Txt           = custTable.name();

        tmpAccountSum.Balance01     = custTable.openBalanceMST();

        tmpAccountSum.insert();

    }

}

 

getCustTmpAccountSum method

This method is mandatory as it returns the table buffer that contains the processed report data. The Dataset uses this buffer to bind the table to the dataset.

/// <summary>

/// This method returns the table buffer that contains processed data

/// </summary>

[SRSReportDataSetAttribute(tableStr(CustTmpAccountSum))]

public CustTmpAccountSum getCustTmpAccountSum()

{

    select * from tmpAccountSum;

 

    return tmpAccountSum;

}

 

After creating the class, go ahead and add a new report the existing report model.

  • Open the previously created Report Model

image

  • Right click on report model, select Add –> Report. Name the report SKL_SampleReportDP
  • Now in the report, go to the Datasets section and create new Dataset using the name CustomerDP
  • The parameters for the new Dataset should be as shown below. The Data Source Type is “Report Data Provider”

image

  • In the query property, click the button image_thumb6
  • This opens a box to select a data provider class
  • Select the class we created before, SKL_SampleReportDP and click “Next”

image

  • In the next tab, Deselect all fields and just select “AccountNum, Balance01 and Txt” fields
  • Click Ok

image

  • This is how the data set looks like

image

  • Now create a new Auto Design as before and name it as CustDP, Select a Layout Template for the report design in Parameters window
  • Now right click on newly created design select “Add” and “Table”
    • Set following properties
      • Name – CustDP
      • Dataset – CustomerDP
      • Style Template – TableStyleAlternatingRowsTemplate
  • You will also notice that the fields are included automatically from Dataset to the “Data” node of the table

image

  • Now right click on the report model and select option “Add SKL_SampleReportProject to AOT”
  • Once the report is created back to AOT, go to AX, find the report in AOT –> SSRS Reports –> Reports, right click and deploy using “Deploy Element” option
  • Once the deployment is successful, create an output type menu item for the report
  • Go to AOT –> Menu Items –> Output, Right click and select “New Menu Item”. Set following properties

image

Now using menu item open and run report. You will notice the same dialog

image

The report looks like as shown below:

image

Build and Deploy Simple Report–Queries

In this post, I will explain about creating a simple AX SSRS Report using the queries from AX AOT. This is what you need to do:

  • Login to AX and open the development workspace
  • Go to AOT –> Queries, right click and select “New Query”
  • Rename the query to “SKL_SampleCustomer”
  • Go to Query’s data source node and right click and select “New Data Source”
  • Rename the data source to “CustTable” and set property table to “CustTable”
  • Now go to the “Fields” node of this query and set property: Dynamic to “Yes”
  • The query looks as shown below

image

  • Save the query
  • Now open visual studio and create a new reporting project by name SKL_SampleReportProject
  • On the reporting model, right click, select “Add” and then Report
  • This will add new report to the project

image

  • Name this report as “SKL_SampleSimpleReportQuery”
  • In the report, Right click on the Dataset node and select “Add Dataset”

image

  • Name the data set as customer
  • On the properties window, ensure following properties are set by default

image

  • In the query property, click the button image
  • This opens up the query selection box to select a Microsoft Dynamics AX Query
  • From the list select “SKL_SampleCustomer” and click Next

image

  • Here you can select required fields. Either you can select all fields or a subset
  • Expand All Fields nodes under the CustTable node to select “AccountNum”
  • Expand Node “All Display Methods” and select “name” and “openBalanceMST”
  • Click “Ok”

image

image

image

  • This will generate the required fields for the dataset

image

  • Now Right click on the designs node, select Add and then “Auto Design”. This creates a new Auto Design and name it as Report

image

  • Select a layout template say “ReportLayoutStyleTemplate”

image

  • Now right click on newly created design select “Add” and “Table”

image

  • Set following properties
    • Name – Cust
    • Dataset – Customer
    • Style Template – TableStyleAlternatingRowsTemplate
  • You will also notice that the fields are included automatically from Dataset to the “Data” node of the table

image

  • Click on Preview once to view the report

image

Note: It may not be possible to preview all reports from VS, especially when there are some internal parameters etc.

  • Now right click on the report model and select option “Add SKL_SampleReportProject to AOT”

image

  • Once the report is added, go to AX, find the report in AOT –> SSRS Reports –> Reports, right click and deploy using “Deploy Element” option
  • Once the deployment is successful, create an output type menu item for the report
  • Go to AOT –> Menu Items –> Output, Right click and select “New Menu Item”. Set following properties

image

  • Now using menu item open and run report.

When you open the menu item, a dialog is automatically made and shown and you will notice that there is also a select button

image

This happens as we had kept the Dynamics Filter property on Dataset in report to “True”. Hence the Reporting framework adds a select button.

The displaying of dialog box can be handled as well. We will cover this topic when we learn about controller classes.

The report will look like this:

image

Note: The name has been intentionally removed from image

Hope this helps you in building your first simple report.

Report Design and Controls

Finally I have sometime on hand that I can use to continue my posts on Reporting framework. I have not been able to update my blog due to various reasons but lets get started again.

In my previous posts I had covered about reporting framework terminologies and reporting project. In this post, let us go through the types of designs available for reports and different controls that are available for a report. Together all these elements form Report Model Elements

The first and foremost model element is the “Report” element itself

Report: The report element represents a report definition. A report definition contains a collection of elements such as datasets, parameters, images, and report designs.

The elements that define a report are located under the node for the report in a model. The report in turn contains Report Designs and Report Controls. A report element can be identified by following symbol:  image

Report Designs

Dynamics AX SSRS reports contains two types of report designs

  • Precision Design
  • Auto Design

Precision Design

A precision design is a report design that is created by using SQL Report Designer (Standard SSRS Report Designer). Precision designs are useful when a very precise layout is required.

These reports are like pre-printed formats where we know the format of the report while designing them.  You can identify a precision design by the following symbol: image

Auto Design

An auto design is a report design that is automatically generated based on the report data. An auto design is created by using drag-and-drop actions, and selecting elements by using Model Editor.

You cannot have specific formats in the Auto Design. This design is useful mostly for tabular and matrix type reports with simple groupings and sorting. You can identify a precision design by the following symbol: image

Report Controls

The report element can have following report controls or elements

  • Dataset
  • Data Region
  • Parameter
  • Filter
  • Grouping
  • Sorting
  • Data Method

Dataset

A dataset identifies data that is displayed in a report. Every report must have one or more datasets. Default data sources that are available for Datasets are “Dynamics AX” and “DynamicsAXOLAP”. The data sets can have data fetched by using anyone of the following options:

  • A query (Dynamics AX AOT query or an OLAP MDX Expression)
  • Report Data Provider
  • Business Logic (C# Business Logic with the reporting project only)
  • AX Enum Provider (Enum values)

A dataset can be identified by image symbol.

Data Region

A data region is an area in a report that displays data. Data can be displayed in following formats

  • Table – Data displayed in columns and rows. Symbol: image
  • Matrix – Data displayed in matrix format. Symbol: image
  • List – Data displayed in list format. Symbol: image
  • Pie Or Doughnut Chart – A chart type report. Symbol: image
  • XY Chart – A chart type reports (Bars, Columns, Lines on XY axis). Symbol: image

Please note that all  these data regions are available in Auto Design report only. The Precision Design has its own standard SSRS report controls.

Parameter

A parameter lets you parameterize data for a report. With the help of parameters, you can filter the data to the required values.

Parameters can be identified by following symbol: image

Filter

A filter is used to filter or restrict the data that is displayed in a report.The Dynamics Filter property on the dataset determines how filters are created for a report. If the Dynamics Filters property on the dataset is set to True, the end user of the report will identify the ranges when they view the report. To manually define the set ranges to filter data on a report, verify the Dynamics Filters property on the dataset is set to False and create your own filters.

Filters can be identified by following symbol: image. Again these filters are available only for Auto Design. The Precision Design has its own way of defining filters

Grouping

A grouping lets you organize data that displays in a report by grouping fields. For Auto Design, you can see a node called grouping for Table or Matrix type data regions. Groupings in Precision Design follow the same procedure that is used in Standard SSRS Reports.

Groupings can be identified by symbol: image

Sorting

A sort lets you control the order in which data displays in a report. For example, you can sort alphabetically by field in ascending or descending order.

Sorting can be identified by symbol: image

Data Method

A data method contains code to retrieve and process data for a report. The code for a data method is written in C# or Visual Basic, depending on which project template is used.

Data Method are designated by following symbol: image

Layout Templates

A layout template specifies the styles that are applied to the header, footer, and body of a report. One layout template can be applied to many reports. Layout Templates are created in a reporting project and are separate from Report Controls.

There are default layout templates available but we can define our own custom templates to suit the needs of the customers.

Layout Templates are identified by symbol: image

Style Templates

A style template specifies the styles that are applied to a data region. When you create a style template, you will notice that there are several types of templates that you can create based on the data region type. A style template can be applied to more than one data region in a report, and it can be applied to data regions in more than one report.

Following are the style templates that you can create (1 per data region type)

  • Table – Symbol: image
  • Matrix – Symbol: image
  • List – Symbol: image
  • Pie Or Doughnut Chart – Symbol: image
  • XY Chart – Symbol: image

Report Data Sources

A data source is a source of data for a report dataset. You can use the predefined data source, which connects to the Microsoft Dynamics AX application database. Or, you can define your own data sources. System by default provides data sources for “Dynamics AX” and “DynamicsAXOLAP”.

Data Sources have symbol image associated with them.

This concludes the report designs and controls.

Reporting Projects–Overview [AX 2012]

A reporting project is used to create SSRS reports for Dynamics AX. A reporting project has following artifacts in Dynamics AX:

  • Visual Studio Dynamics AX Report Models – Contains the managed code, report files and any other related objects like custom style templates etc. Found at AOT –> Visual Studio Projects –> Dynamics AX Model Projects.
  • Visual Studio CSharp / VB Projects – Contains the managed code written either in CSharp or VB. Found at AOT –> Visual Studio Projects –> C Sharp Projects or AOT –> Visual Studio Projects –> Visual Basic Projects.
  • SSRS Reports – Contains the report model elements like RDL etc. They are stored and available in the AOT at AOT –> SSRS Reports –> Reports when it is added to a Microsoft Dynamics AX Report Model in Visual Studio. These reports can be included in multiple report models.
  • Report Style Templates – The reporting project also contains different style templates that can be used for different types of report data regions like Tables, Lists, charts etc. Found at AOT –> SSRS Reports –> Report Style Templates.

Create a Reporting Project in Visual Studio

  • Open Visual Studio 2010
  • Click on File –> New –> Project
  • In the New Project dialog, select “Microsoft Dynamics AX” and then Report Model
  • Set the Name as “SampleReportModel”

image

imageNote: If you don’t see the Microsoft Dynamics AX Options means that the reporting extensions are not installed. Please check the installation once again.

If you wish to add an existing report object from AOT then do the following:

  • Click on View –> Application Explorer (You can use Ctrl + D as well, just like you press to access AOT). This will show you the AOT in visual studio.
  • Now you can access any report object and drag and drop it into project.

imageNote: Visual Studio will connect to the AOS instance defined by current active client configuration in Microsoft Dynamics AX 2012 Client Configuration utility. The layer will also be the same that is defined on active configuration.

image

  • To add the report model project and its related artifacts back to AOT, select the report model, right click and select option: “Add SampleReportModel to AOT” or click File –> Add SampleReportModel to AOT

image

  • Once you add any artifact from VS, it will be visible in AOT.
  • If you want to open the Report Model again, go to AX AOT –> Visual Studio Projects –> Dynamics AX Model Projects. Search for your report model, right and select “Edit”. This opens the model in Visual Studio

image

  • If you select any artifact and right click and select Restore, it will load the artifact back from AOT. Any unsaved changes will be lost (Similar to Restore functionality that we have in MorphX)

image

image

Caution: When you select an artifact and right click, you will see an option as “Delete”. If you click that option, the object will be deleted from AOT from the current logged in layer (If it also exists in lower layers, the object resets back to the next lower level layer. If the object exists in current logged in layer, the object is deleted completely). If you wish the remove an artifact from reporting model or project without deleting, select “Exclude From Project”.

  • To add or view the managed business logic of a report, select the “Data Methods” node of the report, select any one method, right click and select “View Code”. This will open the report business logic programming file along with any reference files

image

This concludes Reporting Project overview topic. In next post, I will explain about creating your first simple report.

Reporting Framework in AX 2012

Dear readers, starting today, I will be writing a series of posts on reporting framework in AX 2012.

We will start with understanding basic concepts in Reporting Framework to examples. These are all the topics that I will be covering one by one:

Many topics to cover. So lets get started.

Reporting Framework Terminologies

As you all know, the reports in AX 2012 have moved to SSRS reporting, so MS has introduced a robust reporting framework wrapping over the basic SSRS reporting functionality. There are many terms used in reporting framework in AX that I will try and explain here:

  • Report Definition Language: RDL is an XML application primarily used with Microsoft SQL Server Reporting Services. RDL is usually written using Visual Studio. AX has Report Definition Language Contract classes that can generate and build the RDL for an AX SSRS report. This contract provides a weakly typed representation of parameters. It contains methods that can be used to get or set values. It also contains a map of parameter names and the SrsReportParameter class. The base class is SrsReportRdlDataContract.

 

  • Report Data Provider (RDP): A framework that helps in building, processing and rendering data to reports. Most of the reports require RDP classes that help in implementing business logic required to process data and provide data in readable, presentable and required formats design. The base class is SrsReportDataProvider. This class has two main sub classes, SrsReportDataProvderBase and SrsReportDataProviderPreProcess. We will discuss about these classes in future posts.

 

  • Report Data Contracts: The Report Data Contracts framework is used to provide and manage the parameters to an SSRS report. The report data contract contains all the other relevant instances like Report Data Provider contracts, print contracts, RDL contracts and query contracts that will be used by a report.

 

  • Printing Contracts: The framework that manages report printing (to different mediums). The base class is SrsPrintDestinationSettings. There are other supporting contracts that are used for printing, we will discuss about them in future posts.

 

  • Query Contracts: This framework manages the queries used to process report data. This framework is also responsible for providing dynamic filters (similar to our ‘Select” buttons on report dialogs that open the Query specification form to filter data on report queries).

 

  • Report Controllers: Report controllers control the report execution and dialog forms. Report controllers can be used to modify report dialogs, validate report parameters and other validations necessary before report execution. The base class is SrsReportRunController. Reports utilizing report controllers can only be used for printing data on client side. Reports controlled by controllers cannot be used in Enterprise Portals.

 

  • Report UI Builders: UI Builders are used to modify the report dialogs at run-time or to add additional parameters and write custom business logic to report dialogs. Ex: You want to perform some task based on data modified for one parameter, that affects other parameters or build a custom lookup etc (something that was provided by RunBaseReport framework class in previous versions. The base class is SrsReportDataContractUIBuilder.

These are some of the basic reporting terminologies that you will be using extensively for reporting in AX.

This concludes the post. Next will be reporting project overview.