How to launch an SSRS Report from AX with pre-loaded parameters

How to launch an SSRS Report from AX with pre-loaded parameters

How to launch an SSRS Report from AX with pre-loaded parameters

So you’ve got a report you want to run in AX, but you want to bypass the parameters screen. You’ve already selected the record you want to run the report on, why should you have to select it again on the parameters screen? With this guide, I’m going to show you how to launch your report directly from a button-click without having to manually select report parameters.

For this guide, I’m going to assume you’ve already created and deployed your report to AX from Visual Studio. The key to accomplishing this task is capturing your data that will be used as parameters upon clicking your report button and utilizing inherited methods on your report controller class to auto-populate your parameters.

Your report controller class should extend the SrsReportRunController class:
class BHSTestRC extends SrsReportRunController

The main method of your report controller class should look similar to this:

public static void main(Args _args)

BHSTestRC    controller = new BHSTestRC(); 
BHSDataTable dataTable;

 dataTable = _args.record() as BHSDataTable;

 controller.parmReportName(ssrsReportStr(SSRSReportName, Report));

Above, we’re taking the args that got passed into this class, and converting them to the type of table we want to pull data from using the _args.record() function. Then we will pass the args into our newly created controller and decide which SSRS report to run. In order to make the report run without showing the parameter screen, we call controller.parmShowDialog(false). This will –you guessed it—disable the parameter screen. The last line will begin the report.

But how does the report know what field to use for what parameter? We can accomplish that in the same report controller class by overwriting the prePromptModifyContract method like this:

protected void prePromptModifyContract()

BHSDataTable    dataTable;
BHSTestContract contract;

  if (this.parmArgs() && this.parmArgs().record())

  contract         = this.parmReportContract().parmRdpContract() as BHSTestContract;

  dataTable        = this.parmArgs().record();


Above, we create another instance of the table we pass in as our args, as well as declare an instance of the report contract class. The contract class should house all the parameters your report will use, as well as parm methods that will access your fields.

We check to see if args were passed in to the class, if so, we create an instance of our contract class, and set the args to our data table. Then we parm the data we need from the args we passed in. This step will ensure that we get the correct data into the proper parameter.

The last step I’ll be going over is showing you how to pass your args into the class in order to use them in the controller. You’ll want to create a new Output menu item that runs your controller class first. Then, on the clicked() method of the button you will use to run your report, place the following code:

Args args = new Args();


 new MenuFunction(menuitemOutputStr(BHSMenuItem), MenuItemType::Output).run(args);

We create a new Args class, and then use the data table to assign a record to args. If you’re on a form and you have a field highlighted in a grid, when you refer to that field, AX will understand that you’re talking about the record that you have highlighted. From there, we create a new MenuFunction using our newly created menu item. At the end we call run(args). This is the action that is responsible for passing the args into our controller class. The code we previously wrote will take care of the rest!

  • Extend SrsReportRunController in your controller class
  • Call controller.parmShowDialog(false) in order to bypass the parameter screen
  • Overwrite the prePromptModifyContract method in order to populate your parameters
  • Create a new menu item that we will use to call into our controller
  • Call in order to pass our args from our form to our report


Share on Google+Tweet about this on TwitterShare on LinkedInShare on FacebookEmail this to someone