简体   繁体   中英

Is it possible to embed javascript into an SSRS Report?

SQL Server reports can embed vbscript and execute client side, but can the same be done with javascript? I think there would be great utility to be able to execute jQuery and CSS manipulation client side to create a more interactive drill down experience.

Are we talking about SQL Server Reporting Services?

If so, I have not ever seen a method to do it. I will admit that the notion makes my skin crawl, though.

Edit

Here is a small example of using JavaScript to open a separate window in a hyperlink.

This blog article may contain even better information for some interesting JavaScript techniques in reporting services.

It sounds to me like Reporting Services is the wrong front end for your job. The RDL (report definition) files are basically XML. I don't know of a way to add code to XML.

If you consider the RDL output to be your "data" then it doesn't really make sense to house any behavior here any way. Instead, you may want to build a front end which can consume the final report output then provide the experience you are looking for.

I know this is an old post however something like this works fine

="javascript:void(window.open('https://" + Parameters!ServerName.Value + "/ReportServer/Pages/ReportViewer.aspx?%2f" + Parameters!Environment.Value + "%2fSSRS+Reports%2fReports%2fVE%2fMy+Reports%2fData+View%2fReport+Name%2f60-Your-Report&rs:Command=Render','_blank'))"

I have an important note to add about this post, if you try to test the javascript in your SSRS report using PREVIEW in Visual Studio (BIDS), it will NOT run in preview mode, but after you deploy the report to an actual report server, then the javascript will work when viewing the report in the web browser. This caused me a lot of confusion I hope to save some others the trouble.

Here is a specific example when and why I frequently use javascript in SSRS. On SSRS reports, it is nice to have hyperlinks to web services or other applications outside of SSRS. In the example below, a "link" field is created in SQL and used in the SSRS report to create a hyperlink to MS Dynamics CRM to a specific Opportunity of a specific Lead.

First, create the http link field with something like this ... ignore the case statement if you do not need to have a different link for different environments.

   ,case
        when @@SERVERNAME like '%CF-PROD%' then 'http://cf-prod-crm01:5559/crm.ashx?id=' + CAST(c.OpportunityID as varchar(36))
        when @@SERVERNAME like '%CF-STG%' then 'http://cf-stg-crm01:5559/crm.ashx?id=' + CAST(c.OpportunityID as varchar(36))
        when @@SERVERNAME like '%CF-QA%' then 'http://cf-qa-crm01:5559/crm.ashx?id=' + CAST(c.OpportunityID as varchar(36))
        when @@SERVERNAME like '%CF-DEV%' then 'http://cf-dev-crm01:5559/crm.ashx?id=' + CAST(c.OpportunityID as varchar(36))
        END AS 'CRMOpportunityLink'

To test, this link should work if you were to copy it and put it manually into a browser for your specific app.

In a report, such as SSRS, you can create a hyperlink using Javascript in the Action area in TextBox, select "Go to URL" and insert the following:

"javascript:void(window.open('" + Fields!CRMOpportunityLink.Value + "','_blank'))")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM