Translate

Tuesday, July 19, 2011

Dynamics AX 2009: SSRS Reports and the role of Business Logic & Data Methods

Dynamics AX 2009: SSRS Reports and the role of Business Logic & Data Methods

This is going to be the first of several posts introducing Data Methods in the context of SSRS reports in AX2009. Before explaining the concepts, we’ll begin by immediately creating a report so that we have something specific to look at.
Platform notes: this demo was done using
  • AX2009 SP1
  • Windows 2008 x64

CREATING A SIMPLE REPORT WITH A DATA METHOD

Let’s create a simple report in Visual Studio. Launch Visual Studio 2008
Create a new Dynamics  AX Reporting Project via File > New > Project
Click OK to create the project
And the project is created with an empty report called '”Report1”
Now let’s add a new Dataset. On the Datasets node, right click and select Add Dataset
And a Dataset called “Dataset1” was created
Now select DataSet1 to see the properties window in the lower right …
And here is a close-up view of the Properties Window

When the Data Source is “Dynamics AX” there are two choices for “Data Source Type”
  • The first is Query – this means an “AX Query”
  • The second is called “Business Logic”
Over the next few blog posts we will focus “Business Logic”

So now, Let’s select “Business Logic”
Now just to help us understand where we are in the process let’s Build the solution and see what happens
As you can see, the Error list shows two messages
  • The first error says that DataSet1 needs to refer to a “data method”
  • The second says that DataSet1 has no fields specified.
So at this point, we have introduced two concepts in the UX: “Business Logic” and “Data Methods”

WHAT IS “BUSINESS LOGIC” IN THE CONTEXT OF AX SSRS REPORTS?

Simply put, it indicates that there is some code (C#) that is going to run on the SSRS server when rendering this report. “Business Logic” as a term can be confusing – it’s best to think of this as meaning “Get Data for the Report from C# code instead of an AX Query”

HOW DOES “BUSINESS LOGIC” RELATE TO “DATA METHODS”

In this context, it means that the Data Method (which is just a C# method) will return data that will be used in the data set.

WHAT DOES A DATA METHOD LOOK LIKE?

To answer this question It’s easiest to create a simple one …

CREATING A SUPER-SIMPLE DATA METHOD

On the DataMethods node, right click and select Add Data Method
You’ll see that DataMethod1 was created
Let’s take a closer look. Right click on DataMethod1 and select View Code
And here is the code…
  And a close up…

The firs thing to note - the Data Method returns string – but returning string is useless if you want to use the Data Method as a source of data!
We need to the Data Method to return a System.Data.DataTable object.

But this isn’t enough. We need to define columns and add some data.
In this example, let’s just create a simple list of names and ages.
First the columns.
Cool, now let’s fill in some fake data.
So we are done with the data method.
What’s interesting here is that that Data Method didn’t talk to AX at all. This is useful for two reasons:
  • This provides a way to get data from non-AX or even non-database sources of data
  • Because there’s no dependency on AX you can prototype a report first without worrying about getting all the AX stuff in order
Now let’s hook up the Data Method to the DataSet
Click open up the Report model by clicking in “Report1.moxl”
Click on DataSet1
And in the properties window click on Query
The ellipsis button will appear. Click it.
And a new dialog will launch asking you to select a data method
So select DataMethod1 and click OK
You can see that the DataSet has picked up the fields from the DataTable automatically


Now let’s build the solution
Look, the error are gone.
At this point you might be tempted to try previewing the report. It you can’t. The reason is simple. The report doesn’t have any designs (i.e. layouts) to render.
So, let’s create one now.
Now, there are complicated,obvious ways of doing this and there is the simple (but not as obvious way). We shall be lazy and use the simple way: drag-and-drop.
Select “DataSet1”

And drag it into the Designs node
 
And you can see a design called “Design1” was auto-magically created.
If you expand the nodes you’ll see the design has been bound to DataSet1 and has added the fields
Now let’s preview the report…

OK, a pretty unexciting report …

You’ll notice the message “The design has validation warnings”.
If you look at the warnings
This is simple letting you know that if you want the report to look nice, you should bind the design to a layout and style template.
Making the report look nice isn’t the point of this post, so I will ignore it for now.

WHAT DATA METHODS ARE GOOD FOR

Now that you know what a Data Method is technically, you can see it is very simple. And now we can discuss the ways you can use them.
First you can use them to access data (their ostensible purpose)
  • AX DATA: If using AX Query is not good enough for you, you can use a Data Method to connect via BC.NET to get the data you want
  • NON-AX DATA: If you want to create a report against a data source an arbitrary data source (for example some RSS/ATOM feed) you can use a data method for this purpose.
Second, you can use Data Methods as an easy way to prototype a report design without worrying about modifying anything in your AX system, As you can see Data methods can simply generate their own data


THE LIMITATIONS OF DATA METHODS

The issue you should be aware of with a data method is that it has to construct a full DataTable and for the report. If your datasets are huge, then your DataTable will be huge and it may affect the performance of your reports.

No comments:

Post a Comment