Using Javascript in SSRS

I will start my first post with javascript injection (there is a personal reason for that).


Well, I always wanted to use scripting in SSRS reports to add the so-called "web flavour" in my reports.
Though, SSRS don't gives you a developer-friendly interface but still its managaeble.And, also let me allow to clear the air that javascript you will use in your reports, works only while you navigate from one report to another.


So, some restrictions are there but I hope future versions will give you more programming edge.
Till that time lets focus on what we have.


In this post, you will be able to see creating:
  • Alerts
  • User Prompt
  • Confirmation Box
  • And widely used, Opening new window


Lets start the basic steps you need to follow,
  1. Create a textbox where you want to inject the javascript code.





















     2.   Add the javascript code in the Go To URL section.
     3.   Deploy your report to a web interface (Report Manager, SharePoint etc.)
     4.   Test your link, you will like it.


Here, are the javascript codes that can be used:


Alert


="javascript:( alert('Hi Guys') )"


User Prompt

  • Based, on the user input you can open a new web page.
="javascript:var name=prompt('Which page do you want to navigate?'); if(name=='google') {void window.open('http://www.google.com',800,800,'_blank')} else {void window.open('http://www.msn.com',800,800,'_blank')}"


Confirmation Box

="javascript:var check=confirm('Do you want to navigate to New report?'); if (check == true) {window.open('http://localhost/Reports/Pages/Report.aspx?ItemPath=%2fReport1','_self')}"


Opening new window

  • When you want to open SSRS report in new window with set of parameters to be passed, you can this piece of code
="javascript:void (window.open('http://localhost/ReportServer/Pages/ReportViewer.aspx?/Folder/Reportname&rs:Command=Render&Param1="& Parameters!Param1.Value & "&Param2=" & Parameters!Param2.Value & "','_blank'))"


Well, these were some basic javascript codes that are used widely.
I will add more to it in my future posts. 
Till then, enjoy blogging!

1 comment:

  1. Hi.. I am using the above to open a .pdf file in a shared location. It works fine if I just put that location in. But if I use the java script call ( ="javascript:void(window.open('"+ Fields!invoice_path.Value + "','_blank'))"). I get an error e.g. The location is e:\PurchScan\2013\1002431B.pdf but when I click on the link, it errors saying " Cannot find 'file:///e:Purchscan3@2431B.pdf'. Make sure the path or Internet address is correct. How do I fix this please? I can see what it is doing.. but don't know how to fix it!

    ReplyDelete