Add a new parameter to SSRS reports in Dynamics 365 for Finance and Operations

Before we explain how to add a new parameter to an SSRS report, let just remind ourselves first that there are two types of report data sets and therefore two types of SSRS reports in Dynamics 365 for Finance and Operations:

  • Query based reports
  • DP (Data Provider) based reports

The procedure of adding new parameters depends on this report type.

How to add a new parameter to a DP based SSRS report

A DP based SSRS report points to a DP class as its data source. A DP class fills temporary tables (actually InMemory, TempDB or Regular) using some business logic and exposes them (using SRSReportDataSetAttributes ) to the related SSRS report as data sets. Also, a DP class points to a Data contract class, which defines and stores values of this SSRS report’s parameters. And finally, a DP class can point to an AOT query which acts as Dynamic parameter. For example:

 

DP based SSRS report > DP class > Data contract (parameters), Dynamic parameter query, Data sets.

If we want to add a new parameter to a DP based report, we need to do this by adding it to the Data contract class. This was a simple procedure in AX 2012 but in Dynamics 365 for Finance and Operations, we must not use overlayering but only extensions. Unfortunately, we cannot simply extend Data contract class since extensions don’t support the attributes making the link to the data contract and dynamic parameter query. So, we have to do it the hard way.

First, we need to create a new contract (to derive from the existing one) with a new parameter, and consequently to create a new DP (to derive from the existing one) that is related to the new contract through the SRSReportParameterAttribute attribute, and then to override the processReport() method in order to use that new parameter. Consequently, we need to duplicate the existing SSRS report and select the new DP class as its data source, and afterwards to extend the existing report menu item to point to the duplicated report. Sometimes, we will need to extend the controller class too and/or implement a Print management event handler; this depends on the report to which we are adding a new parameter.

In order to see the newly added parameter under the Parameters node on the report in AOT, we need to assign the new DP class as a report data source. This will refresh the report’s Parameters. Afterwards, in order to make the newly added parameter appear on the report dialog form, we need to compile and deploy the report.

On how to duplicate a report, extend its menu item and controller class you can learn in more detail in the next chapter.

How to add a new parameter to a Query based SSRS report

A Query based SSRS report points to a query from AOT. A query defines one or more data sets while query ranges becomes report parameters within or outside Dynamic parameter.

Query based SSRS report > Query > Query ranges (parameters), Dynamic parameter, Data sets.

 

In the Why is Container contents report always printed to Screen in D365FO article we saw that Container contents report has a bug that manifests as ignoring the print destination selected in the report dialog and always using the print destination selected in Print management setup instead. This bug can be fixed by adding an additional report parameter Use print management destination as described below.

So, let’s say that we want to add an additional report parameter Use print management destination outside Dynamic query which will not be a query range, but we will use it in the report controller class to change the current execution flow. Namely, depending on this parameter’s value, either the print destination settings selected on the report dialog form or those from Print management setup will be used when the report is executed. After this parameter is added, it will appear on the report dialog form within the Parameters tab and not within the Records to include tab:

Navigation path to this report is: Warehouse management > Inquiries & reports > Container contents report.

Step 1: Duplicating the report

Since Container contents report is a Query based SSRS report it doesn’t have a Data contract class to add a parameter. And since we don’t want to use a query range to define the Use print management destination parameter, we will add it as a separate parameter directly to the Parameters node on the report as shown on the screenshot in Step 2.

However, because we cannot use overlayering, we need to duplicate this report first and then to add the new parameter to it. We can duplicate a report by selecting it in Application Explorer and adding it to our Visual Studio project as shown below.

Step 2: Adding the parameter

We will now open our duplicated SSRS report in Solution Explorer. Expand and right-click on the Parameters node, choose New on the pop-up menu and then select Parameter. This will add a new parameter.

Use Properties to name the parameter as UsePrintManagementDestination and set its Data Type to Boolean, its Default Value to False and its Prompt String to @SYS93922 ('Use print management destination')

In order to make the new parameter appear on the report dialog form, we need to compile and deploy the report first.

After we complete Step 3 and Step 4, and run the report, the newly added parameter will appear on the report dialog form.

Step 3: Extending the controller class

Now we will create a new controller class DocWHSContainerContentsController that will extend WHSContainerContentsController class and implement its main() method in order to be able to use our custom report design. Also, in the same class we will override the runPrintMgmt() method to change the built-in behavior to always use those print settings configured in Print management setup.

Add the following code to the new class:

Step 4: Extending the report output menu item

Now we will create an extension for the report output menu item (WHSContainerContents) in order to enable use of our custom controller class.

Step 5: Adding support for Print management setup

Since ContainerContentsReport report is a Print management report, we have to implement a delegate handler method that will enable our custom report design to be used with Print management setup.

We need to subscribe to the getDefaultReportFormatDelegate() delegate placed in the PrintMgtDocTypeHandlerExt class and implement its handler method in the following way.

After adding the delegate handler build your code and go to Print management setup (Warehouse management > Setup > Warehouse management parameters > Print management tab). You will be able to select our custom report design in the Report format combobox.

 

Result: Using the newly added report parameter

As you can see above, if we turn off the new parameter Use print management destination and select File as the target print destination on the report dialog form, the report will be printed to File and not to the print destination configured in Print management setup.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Docentric respects your privacy. Learn how your comment data is processed >>