Calling Reports via the URL – Drill Downs

In this post we have a look at how ReportServer exposes reports via the URL and how this can be used to implement drilling.

Exporting Reports via the URL

ReportServer exposes all reports via the following URL:
http://SERVER:PORT/reportserverbasedir/reportserver/reportexport

which, for example, allows to incorporate reports into external applications.

The export is controlled using the following parameters:

  • id: The id of the to exported report. Alternatively you can use the parameter key to identify the report
  • key: The key of the to exported report. Can be used as an alternative to id. Note that, one of the two needs to be present
  • format: The export format: for example, html, pdf, csv, excel, png
  • p_: Can be used to set parameter values. Assume you have a parameter with key customernr then you can set the parameter by specifying p_customernr=123. If the parameter takes multiple values these are separated by the pipe character “|”.
For dynamic lists you can additionally configure most aspects of the list using the following parameters
  • c_i: Defines the i-th column. The column is specified using its technical name. Additionally, you can provide an alias for the column. A possible configuration could look like: c_2=ID|fooID. That is, the second column is the column with name ID and its alias is set to fooID.
  • allcolumns: Can be used instead of c_ to simply select all available columns. Note that then it is not possible to further configure the individual columns.
  • agg_i: Configures an aggregation for the i-th column. Possible values are: AVG, COUNT, MAX, MIN, SUM, VARIANCE, COUNT_DISTINCT
  • h_i: Hides the i-th column.
  • or_i: Defines the order of the i-th column. Possible values are: ASC (ascending), DESC (descending).
  • fi_i: Sets an inclusion filter for the i-th column. Multiple filter values are separated by a pipe “|”. For example:  fi_1=FILTER_A|FILTER_B|FILTER_C
  • fri_i: Defines an inclusion range filter for the i-th column. Multiple ranges are separated using the pipe character “|” and the range itself is separated using ” – “.
  • fe_i: Defines exclusion filters similar to fi_i.
  • fre_i: Defines exclusion range filter similar to fi_i.
As an example, have a look at the following URL
http://127.0.0.1:8888/reportserver/reportexport?id=4&c_1=ENTITY_ID|FOO_ID&fri_1=2%20-%205|-%207&c_2=action&c_3=key_field&h_1&or_1=DESC&format=pdf
Note that spaces are encoded as %20 (see, for example, http://www.w3schools.com/tags/ref_urlencode.asp).

Implementing Drills

To implement drills, you can use the export-servlet as described above. Additionally, ReportServer offers some convenience methods to keep track of the path a user took through the maze of possible drills.
ReportServer provides the special parameters _RS_BACKLINK_ID and _RS_BACKLINK_URL for every report execution. If you, for example, want provide a link from a Jasper report to the report with key myKey then use the following URL in your Jasper report:
“http://localhost:8888/reportserver/reportserver/reportexport?key=myKey&format=html&bid=” + $P{_RS_BACKLINK_ID}
where the first part has, naturally, to be replaced by your server’s address. By specifying the parameter bid the “next” report is told where the user came from and is given a URL which points back to the previous report: _RS_BACKLINK_URL. If no backlink is present (for example, for the root of the drill) then _RS_BACKLINK_URL will be empty.