Microsoft Dynamics AX 2012 Reporting Cookbook
上QQ阅读APP看书,第一时间看更新

Opening a report through a controller

A controller plays a key role in orchestrating the entire report life cycle. This recipe will be the first step in using a controller and will explain how a report can be invoked from a controller. The How it works section of this recipe will give you a detailed picture of the report programming model that will help you to understand the other recipes discussed in this chapter.

Getting Ready

To work with this recipe and the others explained here, it is required that you are familiar with the reports discussed in Chapter 1, Understanding and Creating Simple SSRS Reports and Chapter 2, Enhancing Your Report – Visualization and Interaction.

How to do it...

To implement the recipe discussed here and the ones following, create a report with the following specifications:

  1. Create a query PktRdlCustTransList with a limited selection of fields, as detailed in Chapter 1, Understanding and Creating Simple SSRS Reports.
  2. Create a new report in Visual Studio PktRdlCustTransList using the query.
  3. Add an Auto design with grouping by Customer Account.
  4. Go to the Parameters node in the report and add the following unbound parameters:
  5. Build and deploy the report to AX.
  6. Create a class PktRdlCustTransController that extends the SRSReportRunController class.
  7. Add a new main method as shown:
    public static void main(Args args)
    {
      PktRdlCustTransController srs;  
      
      srs = new PktRdlCustTransController ();
      srs.parmReportName(ssrsReportStr(PktRdlCustTransList, CustTransList));
      srs.parmArgs(args);
      srs.startOperation();
    }
  8. The new controller class is now capable of running the report. Press F5 to test run the report.

How it works...

Though we have added only a few lines of code to identify our report, the whole process flows without obstructions. This is orchestrated by the SSRSReportRunController class that is extended by the controller created in this recipe. The detailed description should help you understand the report programming model.

Report programming model

The report programming model in AX 2012 adopts mainly the MVC pattern to be able to decouple the user interface and business logic. An MVP pattern, in simple terms, improves abstraction and creates clarity on responsibilities; consequently, it brings down the growing complexity caused by mashing up the logic that drives the user interface and the business logic. The Runbase framework in AX 2009 is an example of how business logic and UI are put together in the patterns adopted by legacy systems.

The MVC pattern, when applied to a reporting framework, would distribute the responsibilities as specified here:

  • View: This represents the visualization of the report.
  • Model: This represents the data that is generated by processing the parameters.
  • Controller: This represents the parameters and UI builders that will be used to generate the report.
Model

A model for the SSRS report can be an AOT query, Report data provider (RDP), or business logic.

AOT query are queries modeled using the MorphX IDE, while RDPs are classes that extend SRSReportDataProvider. An RDP model is used where complex business logic is involved in computing the data to be rendered. The data is modeled from different sources before being sent to the report.

Controller

The controller implementation in a report is through a group of classes that are bound under the report controller.

  • Report controller: This is the main controller that binds different contract classes and controls the execution of the report starting from parsing the report RDL, binding the contracts and UI builder classes to the report, rendering the UI, invoking the report viewer, and post-processing actions after the report is rendered. It is implemented by the base class SSRSReportRunController and can be extended to apply report-specific controls.

    The report controller uses different contract class, each aimed at different purposes. All contracts involved in a report are referenced through the report data contract.

  • Report data contract: Implemented by SRSReportDataContract, this is the class that holds the different contracts used in a report. Each contract has its designated access method, such as ParmQueryContract and ParmRDLContract, in the report data contract class. Here is a list of contracts present in a report data contract:
  • Report UI builder: This is another controller class that is responsible for building the UI, based on the related contracts. Implemented by SRSReportDataContractUIBuilder, this class extends the SysOperationAutomaticUIBuilder and can be modified for report-specific implementation, overridden to handle UI events, such as validate, and modified.
View

The report model, or the design is the representation of the View and it is designed through the Visual Studio extension for Dynamics AX. Designing a report model was discussed in the previous chapters.

The following diagram will help you to understand the flow, as it happens from the time a request to open a report is invoked, till rendering the report, and after rendering it.