Monday, 7 December 2015

SSRS Open Linked Report In New Window with Javascript

I recently wanted to set op a series of interlinked reports using SQL Server Reporting Services (SSRS) targetting a 2012 instance. I used javascript in a "Custom URL" action on a field to create the link.  Everything looked OK, but further testing I noticed the following type of error was often being generated in in the drill through report:

The report execution xnf441454bs2oh45hqvrkd45 has expired or cannot be found. (rsExecutionNotFound)

The problem was the parameter:  I was using a text field to pass through information for the parameter, and this textual information could include an Ampersand (&).

This is obviously a reserved character, so requires escaping.

To do this, we must utilise SSRS's commands REPLACE and ESCAPE in the custom action.  The easiest way to explain this is in this example:

="javascript:void'" & Globals!ReportServerUrl & "/ReportServer/Pages/ReportViewer.aspx?%2fPhonebook+Reports%2fDepartment&department="
+Replace(Fields!Team.Value,"&","' + escape('&') + '") & "&location="+Replace(Fields!Location.Value,"&","' + escape('&') + '")
 & "&rs:Command=Render=','_blank','')"

Using this format to build the link, I can now open "drill through" reports with a parameter that contains an ampersand, and no longer get the "report execution" error above.   Nice.

Festina Limited Edition Chrono Bike 2015 Men’s Quartz Watch with Brown Dial F16883/1

Click here for a list of the best selling Festina watches this week.

No comments:

Post a Comment