In this post I explain how we can print a report query range in the report header. In this example I used a copy of the “Transaction list per date” Report as an example. This solution is applicable for RDP reports. We can find this report at General Ledger | Inquires and Reports | Ledger Reports
When we open the report, first dialog screen appears, in which we can enter parameters. The fields we can see in the section “Records to include”. are associated with the associated to the range fields of the report query object.
If we look to the report query object we can see that the fields we can see in the “Records to include” section corresponds with the ranges of the query datasource(s). For this particular report we only see the fields which are marked in the screenshot below, and that’s because only ranges with (range parameter) “Open” and “Locked” are visible.
These ranges are not printed automatically in the report as a usual report parameter field. In order to print any range we have to do a number of steps which I describe in this post.
I will demonstrate demonstrate how we can print query range field “Voucher” from the dialog as a parameter field in the report header.
We have to make changes in the following report classes:
Here we add following parm method, which will be used as report parameter which holds the query range. This parameter is defaulted by the Controller class (see 3. Controller).
Here we create a new dialog field which will be used as parameter for the report It will be defaulted by the parameter value from the contract class(See 1. Contract). Steps:
In the postRun method, add following logic (below the super()):
In this class, we extract the query range value and assign it as default value to the contract parameter (see 1 Contract). This logic is written in the “preRunModifyContract” method. The preRunModifyContract will be called after clicking dialog’s OK button, so the information we see in the report is the most recent. There is another method “prePromptModifyContract” which will be called at the moment user cliks the report link. We will use this method to initialize the contract parameter value as we would like to get the (fresh) value from the report query dialog.
Here are the code changes:
Declaration of the contract class
Defaulting contract parmVoucherRange method with the query build value, at the end of the method. In this logic we catch the report query and it in a map. Via a map enumerator we are able to extract the report query, and from here we can put our selected range in a query build range and assign the value of the query build range to the parm method “parmVoucherRange” of the contract class. The preRunModify contract is called after eventually changes are made in the report dialog, so we always get most actual value of the range.
Changes will be in effect once we compile and deploy the report.
Now we have to do the following changes in the SSRS report object, so that the report will print the changes. If we open the “parameters” section, we can find the Voucher range parameter. As the parameter is defaulted, by the report’s query range, there is no need for the user to alter this field, so we will hide it.
In the parameter property window we can set Visibility to ‘Hidden’
In the report designer we need to add the Range to make it visible in the report header section. Open the report designer:
Now we can add new text boxes, one for the label (“Range”) and the another with the actual range value.
Right click the textbox and select ‘Expression’
Here we enter the following logic in the “Set expression for: Value” area:
For the textbox label “Range”:
For the range:
Nb we saw in the parameter section that the range parameter name is “LedgerTransListDateDS_FOXVoucherRange” which we use for the “Set expression for : value.
“Set expression for: Value” for the query range is:
Changes will be in effect once the report is complied and deployed.