Header Ads Widget

📊 Building an SSRS Report in D365FO Using RDP, Contract, and Controller Classes

 Author: Sai Krishna

Creating SSRS reports in D365FO using the RDP (Report Data Provider) pattern allows for complex data processing and customization. This guide walks you through the steps to build an SSRS report using RDP, Contract, and Controller classes.

Tags: D365FO SSRS Report, RDP Class, Contract Class, Controller Class, TempDB, Microsoft Dynamics AX, Report Development


🧱 Step 1: Create a Temporary Table

Design a temporary table (e.g., SK_PerdiemTempTable) with the necessary fields to store the data for the report. Set the table's TableType property to InMemory or TempDB based on your requirements.


🔍 Step 2: Define a Query

Create a query (e.g., SK_PerdiemQuery) that joins the relevant tables (PerdiemHeader, PerdiemLine, etc.) and includes the fields needed for the report.


📄 Step 3: Develop the Data Contract Class

The Data Contract class defines the parameters that will be passed to the report.

x++
[DataContractAttribute] class SK_PerdiemContract { PerdiemStatus _perdiemStatus; [DataMemberAttribute("PerdiemStatus"), SysOperationLabelAttribute("Perdiem Status"), SysOperationHelpTextAttribute("Select the status of the perdiem"), SysOperationDisplayOrderAttribute("1")] public PerdiemStatus parmPerdiemStatus(PerdiemStatus _status = _perdiemStatus) { _perdiemStatus = _status; return _perdiemStatus; } }

🧠 Step 4: Create the RDP Class

The RDP class processes the data and populates the temporary table.

x++
[SRSReportQueryAttribute(queryStr(SK_PerdiemQuery)), SRSReportParameterAttribute(classStr(SK_PerdiemContract))] public class SK_PerdiemRDP extends SRSReportDataProviderBase { SK_PerdiemTempTable tempPerdiemTable; PerdiemStatus selectedStatus; private void getReportParameters() { SK_PerdiemContract contract = this.parmDataContract() as SK_PerdiemContract; selectedStatus = contract.parmPerdiemStatus(); } private void insertIntoTempTable(PerdiemHeader _header, PerdiemLine _line) { tempPerdiemTable.PerdiemRequestID = _header.PerdiemRequestID; tempPerdiemTable.EmployeeNumber = _header.EmplNum; tempPerdiemTable.EmployeeName = _header.EmplName; tempPerdiemTable.ApplicationDate = _header.ApplicationDate; tempPerdiemTable.Status = _header.PerdiemStatus; tempPerdiemTable.Purpose = _header.PurposeOfTravelForPerdiem; tempPerdiemTable.CountryRegionId = _line.CountryRegionId; tempPerdiemTable.CurrencyCode = _line.CurrencyCode; tempPerdiemTable.StartDate = _line.StartDate; tempPerdiemTable.EndDate = _line.EndDate; tempPerdiemTable.TotalDays = _line.TotalNoOfDay; tempPerdiemTable.TotalAmount = _line.TotalAmount; tempPerdiemTable.UserID = curUserId(); CompanyInfo companyInfo = CompanyInfo::find(); tempPerdiemTable.CompanyLogo = CompanyImage::findByRecord(companyInfo).Image; tempPerdiemTable.insert(); } public void processReport() { this.getReportParameters(); QueryRun queryRun = new QueryRun(this.parmQuery()); while (queryRun.next()) { PerdiemHeader header = queryRun.get(tableNum(PerdiemHeader)); PerdiemLine line = queryRun.get(tableNum(PerdiemLine)); if (header.PerdiemStatus == selectedStatus) { this.insertIntoTempTable(header, line); } } } [SRSReportDataSetAttribute(tableStr(SK_PerdiemTempTable))] public SK_PerdiemTempTable getPerdiemData() { select tempPerdiemTable; return tempPerdiemTable; } }

🎮 Step 5: Implement the Controller Class

The Controller class manages the report execution and parameter passing.

x++
class SK_PerdiemReportController extends SrsReportRunController { #define.ReportName('SK_PerdiemReport.Report') public static void main(Args _args) { SK_PerdiemReportController controller = new SK_PerdiemReportController(); controller.parmReportName(#ReportName); controller.parmArgs(_args); controller.parmShowDialog(true); controller.startOperation(); } }

🖥️ Step 6: Design the Report in Visual Studio

  1. Create a New Report: In Visual Studio, add a new report and name it SK_PerdiemReport.

  2. Add Dataset: Use the SK_PerdiemTempTable as the dataset.

  3. Design Layout: Drag and drop fields from the dataset to design the report layout as per your requirements.

  4. Add Parameters: Include parameters defined in the Data Contract class.

  5. Deploy the Report: Deploy the report to the D365FO environment.


🧪 Step 7: Test the Report

  1. Navigate to the Report: In D365FO, go to the menu item linked to the report.

  2. Provide Parameters: Enter the required parameters in the dialog.

  3. Run the Report: Execute the report and verify the output.


📝 Additional Tips

  • Date and Time in Report: To display the current date and time in the report, use the following expression in the report design:

    plaintext
    =Microsoft.Dynamics.Framework.Reports.DataMethodUtility.ConvertUtcToAxUserTimeZoneForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, System.DateTime.UtcNow, "g", Parameters!AX_RenderingCulture.Value)
  • Page Numbers: To display page numbers, use:

    plaintext
    ="Page " & Globals!PageNumber & " of " & Globals!TotalPages
  • Company Name: To display the company name:

    plaintext
    =Microsoft.Dynamics.Framework.Reports.DataMethodUtility.GetFullCompanyNameForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value)

By following these steps, you can create a robust SSRS report in D365FO using the RDP pattern, allowing for complex data manipulation and customized reporting.

Post a Comment

0 Comments