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

image

Create a new Dynamics  AX Reporting Project via File > New > Project

image

Click OK to create the project

image

And the project is created with an empty report called ‘”Report1”

image

Now let’s add a new Dataset. On the Datasets node, right click and select Add Dataset

image

And a Dataset called “Dataset1” was created

image

Now select DataSet1 to see the properties window in the lower right …

image

And here is a close-up view of the Properties Window

image

 

When the Data Source is “Dynamics AX” there are two choices for “Data Source Type”

image

  • 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”

image

image

Now just to help us understand where we are in the process let’s Build the solution and see what happens

image

As you can see, the Error list shows two messages

image

image

  • 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

image

You’ll see that DataMethod1 was created

image

Let’s take a closer look. Right click on DataMethod1 and select View Code

image

And here is the code…

image  And a close up…

 

image

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.

 

image

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.

image

 

Cool, now let’s fill in some fake data.

image

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”

image

Click on DataSet1

image

And in the properties window click on Query

image

The ellipsis button will appear. Click it.

image

And a new dialog will launch asking you to select a data method

image

So select DataMethod1 and click OK

image

You can see that the DataSet has picked up the fields from the DataTable automatically

image

image

Now let’s build the solution

image

Look, the error are gone.

image

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”

image

 

And drag it into the Designs node

 image

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

image

Now let’s preview the report…

image

 

image

OK, a pretty unexciting report …

image

 

You’ll notice the message “The design has validation warnings”.

If you look at the warnings

image

image

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

 

image

 

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.


Comments (0)

Skip to main content