Use JavaScript to open a second SSRS report window

Within SSRS reports, you may sometimes want to show more details for a given record but don’t necessarily want to add it to the existing report or go to another report. Here is a neat solution. You can add JavaScript to your report and have a second report window pop up with the details! Let’s take a look at how we can do this. First you will need to create two reports; your main report and the second report that will show up on the pop up window with details.

On the first report you will need to decide where you want your user to click to pull up the second report. In our example here, we have a reservation list. We will be clicking on the Customer Name to get more details about that customer.

Report designer

Next, we will go to the text box properties and then the Action tab. Select ‘Go to URL’ and then click on the expression button.

Text box action tab

Here is where the magic happens. Using SSRS URL Access, we will send commands to the report server and pull up the second report.

Javascript to open a second window

Here is the code we will use for our reports.

="javascript:void window.open(" &"'"& Globals!ReportServerUrl &"/Pages/ReportViewer.aspx?"
&Globals!ReportFolder &"/Customer+Details&rc:Parameters=False
&CustomerID="& Fields!CustomerID.Value &"
','CustomerDetailsWindow','left=370,top=180,width=940,height=300,status=no,menubar=no,scrollbars=no,location=yes'" & ")"

The first line uses a global variable to populate the report server URL and report viewer. The second line puts in a report folder value, and specifies a report name. Our pop up report is called ‘Customer Details.rdl’, but as you can see here we just specify the report name without the .rdl at the end. We will also pass in a parameter option of ‘Parameters=False’ on the second line. This will turn off the parameter drop down box on the controls. We don’t want our report to give the option of selecting a different customer. If you need to pass more than one parameter, simply copy the third line and paste the copy below line three and modify with the new parameter values. In our example, the third line specifies the parameter name (CustomerID) on the second report, and the value from the main report. For this report, we will be passing in (Fields!CustomerID.Value). Finally, on the last line we specify some additional properties that we want the pop up window to have such as the width and height.

We only use one URL parameter value (Parameters=False) in our example. However, there are quite a few more that can help customize your secondary report window. To find more information about parameter values, follow this link:

If you are having a hard time getting your report to work, I suggest first going to your report server URL (http://YourServer/reportserver), browse to your report and try setting your SSRS parameter strings to make sure you have the correct syntax. You should then be able to pull it apart and insert it into your JavaScript expression.

Here is a screenshot of our final solution. When we click on the Customer Name, we get a second report with additional customer information.

Two report windows open

More information on using SSRS URL Access can be found here:
http://msdn.microsoft.com/en-us/library/ms153586

Advertisement

12 responses to “Use JavaScript to open a second SSRS report window

  1. Best article on this subject I’ve come across so far, simple and clear for the non-java person like myself. Do you have any ideas how to pass a report parameter value (rather than a table value from a dataset) from the originating report to the target report using javascript? I have tried this without success so far.

  2. WOW!! i’ve been trying to resolve this issue for quite a while…thank you thank you thank you for such a detailed and well-written instructional. i’m only 9 months into my SQL/SSRS career and i understood everything perfectly, and i got it to work! you, sir, are a Guru!!! 🙂

  3. I have tried above example but its working fine on local machine but its not working when i send the paramters in url it does not open new report on client server.How to solve it.

  4. gracias, siempre estaba buscando algo asi, por fin lo encontre, tengo otra pregunta, yo puedo crear algun grafico y que este contenga movimiento…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s