We just published a screencast that started exploring a new concept in AX 2012: the Report Programming Model and Report Data Providers.
In addition to the screencast I wanted to use this post to elaborate on the topic shown in the screencast.
BUSINESS LOGIC IN REPORTS
When I discuss "business logic" in this post, I am referring to code that is used to generate data for use in reports. In Dynamic AX 2009 there really is no great way to reuse your X++ code in an SSRS report. This is one reason I recommend that everyone stick with simple query-based reports in Dynamics AX 2009. Of course, we wanted to make this much easier in Dynamics AX 2012 and that is why we created a concept called the Report Data Provider.
WHAT IS A REPORT DATA PROVIDER?
It is a X++ code-based way of generating data for reports. This code can use any technique to generate data for Dynamics AX 2012 Reports. It is the correct and supported way to reuse your existing X++ code in Dynamics AX 2012 reports.
HOW IT WORKS
The simplest summary is that you create a table – usually a temp table. And then a class – this is known as the Report Data Provider class. When the report is run, the class populated the temp table with data. One the data completely populated it is transferred to the SSRS server.
CONSTRUCTING THE TEMP TABLE
First, decide what fields you need in your report. Then create a table with those fields. You MUST assign Extended Data Types to those fields. Then set the TableType property to "TempDB"
Here’s a simple table with just two fields
Notice that that Extended Data Type has been set for the Name field
And for the ID field
And then notice that the TableType property has been set on the table to "TempDB".
CONSTRUCTING THE DATA PROVIDER CLASS
The simplest RDP class has only three components – they are shown below.
The classDeclaration is simple. The RDP Class MUST extend SRSReportDataProviderBase. Also it has a reference to the temp table.
The next method is needed for the AX 2012 reporting framework to retrieve data from the temp table. The SRSReportDataSetAttribute attribute MUST be used to identify the temp table to the framework. The specific name of this method is not important – the attribute is what counts.
The processReport() method MUST be implemented when a class extends SRSReportDataProviderBase. In this example, you can see that this method is a completely code-based way of generating data into the report.
And that’s it for the basics. Now you have a datasource that can be used in an X++ Report.
PARTING THOUGHTS: THIS IS IMPORTANT TO LEARN
In practice, many or most of the reports you’ll work with or implement will be built on Report Data Providers. Above I have provided the very simplest implementation. Master it. Once you get AX 2012 implement this over and over until you have memorized the steps because you’ll be doing quite a bit of it in the future.