Developing SSRS Reports Using Report Data Provider in D365F&O
In this article, we will cover the Report Data Provider (RDP) class and the Report Contract class. We will also learn how to implement these classes for reporting needs in Dynamics 365 Finance & Operations and create a report using the RDP class via a step-by-step walkthrough.
Report Data Provider (RDP) Framework
A Report Data Provider (RDP) class is an X++ class used to access and process data for a report. An RDP class is an appropriate data source type when the following conditions are met:
- You cannot query directly for the data you want to render on a report.
- The data to be processed and displayed is complex and requires specific business logic.
Report Data Provider Class
This is an X++ class used to access and process data for an SSRS report. The RDP class processes business logic based on specified parameters and/or queries and returns a dataset to the reporting services.
To create an RDP class in D365F&O, you must extend the class with SRSReportDataProviderBase. This indicates that the class will be used by reporting services to process data.
Two important attributes are used in RDP classes:
- SRSReportQueryAttribute: Specifies which Query will be used in this report. If the RDP class uses a defined Query to process data, define this attribute at the beginning of the class.
- SRSReportParameterAttribute: Defines the data contract class that will be used by this report to prompt for parameter values. If the RDP class contains any parameters, define this attribute at the beginning of the class.
Note: Both attributes are optional. If the report does not use a query or does not require parameters to filter data, these attributes do not need to be used.
Data Contract Class
This class is used to define one or more parameters that will be used in an SSRS report. We can define any number of parameters using X++ statements of any data type, which can be passed to the RDP class.
A data contract class is an X++ class that contains parm methods with the DataMemberAttribute defined at the beginning of the method.
Table
A table is used as the dataset to store data for the report. The RDP class processes the data and stores it in the table, which is then used by the SSRS report to render data.
A table can be a temporary table (InMemory or TempDB) or a regular table, but it is a best practice to use a temporary table. TempDB is normally used for larger datasets to improve performance, while InMemory is used for smaller datasets.
Scenario
We need to display a list of customer transactions. It is a relatively simple report, but we will build it using the RDP framework to demonstrate the process.
Steps:- Create a temporary table.
- Define the report parameters (Contract).
- Add business logic for the report (RDP).
- Create a reporting project.
- Bind a report to the RDP class.
Step 1: Create a Project
Open Visual Studio as an administrator.
- Go to File > New > Project.
- Select Finance and Operations.
- Create a new project and rename it
CustTransactionRDPDemo.
Step 2: Create a Temporary Table
- Right-click your project in Solution Explorer, select Add > New Item.
- Select Table and name it
CustTransactionTMP. - In the properties window, locate the TableType property and set it to
TempDB.
Add Fields:
Decide which fields are required for the report and add them to the table. For this example, add the following fields (types based on CustTrans):
- AccountNum
- AmountMST
- Invoice
- TransDate
- TransType
- Txt
- Voucher
- CustName
Save the table.
Step 3: Create a Query
- Right-click your project, select Add > New Item.
- Select Query and name it
CustomerTransactionQuery. - Open the query designer and drag the
CustTranstable into the Data Sources node. - Save the query.
Step 4: Define Report Parameters (Data Contract)
We require three parameters: Customer Account, From Date, and To Date.
- Create a new Class named
CustomerTransactionContract. - Implement the code below. Note the use of
[DataContractAttribute].
[DataContractAttribute]
class CustomerTransactionContract
{
CustAccount CustomerAccount;
TransDate FromDate;
TransDate ToDate;
[DataMemberAttribute(identifierStr(CustAccount)),
SysOperationLabelAttribute ("Customer Account"),
SysOperationHelpTextAttribute("Customer Account"),
SysOperationDisplayOrderAttribute("1")]
public CustAccount parmCustomerAccount(CustAccount _CustomerAccount = CustomerAccount)
{
CustomerAccount = _CustomerAccount;
return CustomerAccount;
}
[DataMemberAttribute(identifierStr(FromDate)),
SysOperationLabelAttribute ("From Date"),
SysOperationHelpTextAttribute("FromDate"),
SysOperationDisplayOrderAttribute("2")]
public TransDate parmFromDate(TransDate _FromDate = FromDate)
{
FromDate = _FromDate;
return FromDate;
}
[DataMemberAttribute(identifierStr(ToDate)),
SysOperationLabelAttribute ("To Date"),
SysOperationHelpTextAttribute("To Date"),
SysOperationDisplayOrderAttribute("3")]
public TransDate parmToDate(TransDate _ToDate = ToDate)
{
ToDate = _ToDate;
return ToDate;
}
}
Step 5: Add Business Logic (RDP Class)
Create the Data Provider class containing the business logic to populate the temporary table.
- Create a new Class named
CustomerTransactionDP. - Extend
SRSReportDataProviderBase. - Add the
SRSReportParameterAttributeandSRSReportQueryAttributeto link your Contract and Query.
[SRSReportParameterAttribute(classstr(CustomerTransactionContract)),
SRSReportQueryAttribute(queryStr(CustomerTransactionQuery))]
class CustomerTransactionDP extends SRSReportDataProviderBase
{
CustTransactionTMP _CustTransactionTMP;
[SRSReportDataSetAttribute("CustTransactionTMP")]
public CustTransactionTMP getCustTransactionTMP()
{
select * from _CustTransactionTMP;
return _CustTransactionTMP;
}
public void processReport()
{
TransDate _FromDate;
TransDate _Todate;
AccountNum _CustAccount;
CustomerTransactionContract dataContract;
Query query;
QueryRun queryRun;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
QueryBuildRange TransDateFilter;
CustTrans querycusttrans;
// Get parameters
query = this.parmQuery();
dataContract = this.parmDataContract();
_CustAccount = dataContract.parmCustomerAccount();
_FromDate = dataContract.parmFromDate();
_Todate= dataContract.parmToDate();
// Add ranges dynamically based on contract
queryBuildDataSource = query.dataSourceTable(tablenum(CustTrans));
if (_CustAccount)
{
queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTrans, AccountNum));
if (!queryBuildRange)
{
queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTrans, AccountNum));
}
queryBuildRange.value(_CustAccount);
}
TransDateFilter = SysQuery::findOrCreateRange(query.datasourceTable(tableNum(CustTrans)), fieldNum(CustTrans, TransDate));
TransDateFilter.value(SysQuery::range(_FromDate, _Todate));
// Execute query and populate temp table
queryRun = new QueryRun(query);
ttsbegin;
while(queryRun.next())
{
_CustTransactionTMP.clear();
querycusttrans = queryRun.get(tablenum(CustTrans));
_CustTransactionTMP.AccountNum = querycusttrans.AccountNum;
_CustTransactionTMP.AmountMST = querycusttrans.AmountMST;
_CustTransactionTMP.Invoice = querycusttrans.Invoice;
_CustTransactionTMP.TransDate = querycusttrans.TransDate;
_CustTransactionTMP.TransType = querycusttrans.TransType;
_CustTransactionTMP.Txt = querycusttrans.Txt;
_CustTransactionTMP.Voucher = querycusttrans.Voucher;
_CustTransactionTMP.CustName = CustTable::find(querycusttrans.AccountNum).name();
_CustTransactionTMP.insert();
}
ttscommit;
}
}
Build the Solution: Right-click your project in Solution Explorer and select Build. Ensure there are no errors.
Step 6: Create the Report
- Right-click your project, select Add > New Item.
- Select Report and name it
CustTransRDPReport.
Dataset Configuration:
- In the Report Designer (solution explorer), right-click Datasets and select Add Dataset.
- Name it
CustTransaction. - In the Properties window, change the Data Source Type to
Report Data Provider. - Click the ellipsis (
...) on the Query property field. - In the selection dialog, find and select the
CustomerTransactionDPclass created in Step 5.
Parameters:
Expand the Parameters node of the report. Open the properties of the CustAccount parameter. Set Allow Blank to True and Nullable to True. This ensures that if no customer is selected, the report runs for all customers.
Design:
There are two types of designs:
- Auto Design: Visual Studio creates a design based on the dataset.
- Precision Design: Allows custom placement and complex layouts.
For this demo, we will use Precision Design:
- Right-click the Designs node and select Add > Precision Design. Name it
Report. - Double-click the design to open the SQL Report Designer canvas.
- Open the Toolbox and drag a Table element onto the design surface.
- Drag and drop fields from your dataset (on the left) into the cells of the Table control.
Save and Build the solution again to deploy the report.
Step 7: Create a Menu Item
To open the report in D365F&O, a menu item is required.
- Right-click your project, select Add > New Item.
- Select Output Menu Item.
- Name it
CustomerTransactionReportRDP. - Set the following properties in the property pane:
- ObjectType:
SSRSReport - Object:
CustTransRDPReport(The name of your report) - ReportDesign:
Report(The name of your precision design)
- ObjectType:
Running the Report
- Right-click the Menu Item and select Set as Startup Object.
- Click Start in Visual Studio to launch the D365F&O client.
- The Report Dialog will appear automatically once the browser loads.
Set values for "From Date" and "To Date" and run the report. The report will generate based on the logic defined in your RDP class.
I'm glad you enjoyed the post. Thanks for shearing about this I thinks its very hopeful post and very important post for us.Thanks for your great and helpful presentation I like your good service.I always appreciate your post.
ReplyDeletepreferred providers
SSRS Interview Questions Answers
ReplyDeleteGreat Article.. Thank you for sharing..
ReplyDeleteD365 Finance and Operations Training
D365 Ax Technical Online Training
D365 Finance and Operations Online Training
Microsoft Dynamics AX Technical Training
Microsoft Dynamics AX Training
Very Useful..... Thanks for Sharing...
ReplyDeleteBest Online Summer Internship Training
Summer Training in Noida
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Best Online Training Company
Best Online Internship Training Company
Best Online Python Training Company
Best Online Data Science Training Company
Best Online Machine Learning Training Company
Best Online Digital Marketing Training Company
Best Online Winter Training in Noida
Best Data Science Course Training in Bangalore
Best Data Science Course Training in Hyderabad
Best Data Science Course Training in Pune
Data Science Course Training Certification in USA
Best Data Science Certification Course Online
Wonderful article . Thanks for sharing.
ReplyDeleteAx Technical D365
D365 Ax Technical Online Training
D365 Finance and Operations Online Training
Microsoft Dynamics AX Technical Training
Microsoft Dynamics AX Training
Microsoft Dynamics AX Technical Training in Hyderabad
Dynamics 365 Training
Microsoft Dynamics 365 Online Training Course
Such an informative post Thanks for sharing. We are providing the best services. Click on the links below to visit our website.
ReplyDeleteMicroSoft Dynamics Ax Training Online
MicroSoft Dynamics Ax Training
MicroSoft Dynamics 365 Training Courses
MicroSoft Ax Training
Dynamics 365 Online Course
MicroSoft Dynamics Ax Course
MicroSoft Dynamics Ax Online Training
Such an informative post Thanks for sharing. We are providing the best services. Click on the links below to visit our website.
ReplyDeleteMicroSoft Dynamics Ax Training Online
MicroSoft Dynamics Ax Training
MicroSoft Dynamics 365 Training Courses
MicroSoft Ax Training
Dynamics 365 Online Course
MicroSoft Dynamics Ax Course
MicroSoft Dynamics Ax Online Training
Such an informative post Thanks for sharing. We are providing the best services. Click on the links below to visit our website.
ReplyDeleteMicroSoft Dynamics Ax Training Online
MicroSoft Dynamics Ax Training
MicroSoft Dynamics 365 Training Courses
MicroSoft Ax Training
Dynamics 365 Online Course
MicroSoft Dynamics Ax Course
MicroSoft Dynamics Ax Online Training