Step
4: Create a Report Data Provider (RDP) class
A
report data provider (RDP) class is an X++ class that is used to access and
process data for a report. An
RDP
class extends the SRSReportDataProviderBase class.
The following
example illustrates the code to declare a RDP class.
/// <summary>
/// The <c> HS_CustBalanceDP</c> class is
the report data provider class for the HS_CustBalanceReport report.
/// </summary>
/// <remarks>
/// This is a sample class.
Created by Vimal on Nov 18, 2014
/// </remarks>
[
SRSReportQueryAttribute(querystr(HS_CustBalance)),
SRSReportParameterAttribute(classStr(HS_CustBalanceContract))
]
class
HS_CustBalanceDP extends SRSReportDataProviderBase
//class HS_CustBalanceDP extends SRSReportDataProviderPreProcess
{
HS_CustBalanceTableTMP custBalanceTableTMP;
AccountNum
accountNum
;’
}
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.
Add getHS_CustBalanceTableTMP
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(“HS_CustBalanceTableTMP”))
]
public
HS_CustBalanceTableTMP getHS_CustBalanceTableTMP()
{
select * from custBalanceTableTMP;
return
custBalanceTableTMP;
}
Add getReportParameter
method
/// <summary>
/// This method
processes the report parameters
/// </summary>
Private
void getReportParameter()
{
HS_CustBalanceContract
contract = this.parmDataContract();
if
(contract)
{
accountNum
= contract.parmAccountNum();
}
}
Add insertHS_CustBalanceTableTMP
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 HS_CustBalanceTableTMP table
/// </summary>
Private
void insertHS_CustBalanceTableTMP()
{
QueryRun
queryRun
= new QueryRun(this.parmQuery());
CustTable custTable;
while
(queryRun.next())
{
custTable
= queryRun.get(tableNum(CustTable));
custBalanceTableTMP.AccountNum = custTable.AccountNum;
custBalanceTableTMP.Name = custTable.Name();
custBalanceTableTMP.Balance = custTable.openBalanceMST();
custBalanceTableTMP..insert();
}
}
Add processReport
method (The processReport
method is the entry point for calculating the report data for dataset. Here is
the method for our sample class)
/// <summary>
/// This method
processes the business logic and executes first while accessing SSRS report
/// </summary>
[
SysEntryPointAttribute(false)
]
Public
void processReport()
{
this. getReportParameter();
this.
insertHS_CustBalanceTableTMP();
}
Step
5: Create a Report Model in Visual Studio
üGo to File menu
and select New
project (new
project window will get appear)
üSelect Microsoft
Dynamics AX
under Installed
templates
üSelect Report
Model in
the right pane
üName the project as “HS_CustBalanceReport” and
press OK (Solution explorer will get appear with newly created project)
üRight click on the project and go to Add and
select Report
üA report will be added to the project
with the name “Report1″. Rename the report HS_CustBalanceReport
üExpand the report and need to add report
dataset
üRight click on the dataset and select Add
Dataset and
name the dataset
üIn the dataset properties window select
Data Source Type “Report Data Provider” then
select Query
field an ellipse button appears
üClick on ellipse button and select a
Microsoft Dynamics AX Report Data Provider
üClick on Next and
select the fields you want to display in the report and press OK (Only
the selected fields will be shown in the report
dataset)
üGo to Design node, right click and Add
Auto Design
üDrag the dataset and drop into Auto
Design node, A
table will be created which contain all the fields present in the data set.
These fields will appear in the same order in the report. So if you want to
arrange the fields, right click the field and select either move up or move
down.
üset the formatting in Properties window.
Once report is done then follow these steps
üIn Solution explorer, Right click on
project and select Add HS_CustBalanceReport
to AOT (VS
Project and report will be added in AX AOT)
üIn the Solution Explorer, right-click the
project, and select Build
üIn the Solution Explorer, right-click the
project, and select Deploy
üCross check- Project: Go to
AOT->
Visual Studio Projects-> Dynamics AX Model projects and
expand, search your project
üCross check- Report: Go to
AOT->
SSRS Reports-> Reports and expand, search your report
Step
6: Create an Output type menu item “HS_CustBalanceReport”
set the menu item’s basic properties
Step 7:
Run the report through this menu item
Enjoy coding with MS