16

I have a report that passes an id that is used to access salesforce.com. I want to open SFDC as a new page from the URL hyperlink. However, nothing I do seems to be working!

="javascript:void(window.open('https://na5.salesforce.com/& Fields!id.Value,'_blank'))"

Fields!id!Value is the SFDC id that is being passed. I'm trying this in the expression to no avail!

I know it is something VERY simple but I'm just not finding it. Thanks in advance for the assistance!

UPDATE!!!

Figured it out!!! For the record, the syntax is:

="javascript:void(window.open('https://na5.salesforce.com/" & Fields!id.Value & "'))"

Keith Johnson
  • 173
  • 1
  • 1
  • 6

4 Answers4

11

For the record, the problem with your original syntax was that you were trying to go from referencing an SSRS field to entering a string without separating the two properly. If you wanted your previous syntax to work (without removing the target window's name (i.e., '_blank'), you would do it like this:

="javascript:void(window.open('https://na5.salesforce.com/" & Fields!id.Value & "','_blank'))"

I struggled with this for a long time, but you can make these pretty complex as long as you're careful to put everything together correctly. You can also add multiple javascript commands (but no functions) in the same action expression. Below is one of my most complicated SSRS Go-to-URL Action commands:

="Javascript:" 
    & IIF(left(Fields!Name.Value,11)="RESTRICTED-", 
        "alert('Restricted!'); ","") & IIF(Fields!Name_Alert.Value = 1, "alert('Alternate Alert!'); ","") 
    & "void(window.open('" 
    & Globals!ReportServerUrl 
    & "/Pages/ReportViewer.aspx?%2fJPD%2fPO_Dashboard%2fJuvenile_Profile&rs:Command=Render" 
    & "&rc:Parameters=true" 
    & "&Emp_Number=" 
    & Parameters!Param1.Value 
    & “&ID=" & Fields!ID.Value & "'));"

The key is to make sure that any and all necessary single quotes required by javascript show up inside a string (i.e., "'").

Christopher Brown
  • 2,170
  • 1
  • 13
  • 19
  • 1
    Per Stefan Steiger's point regarding PDF and Excel reports, you can easily encapsulate the JavaScript portion of the URL into an IIF statement that removes the JavaScript if exported to a PDF or Excel version using built-in RenderFormat fields if you're using SSRS 2008 R2 or later. If you're using 2008 or before, you can achieve the same result with a boolean parameter. If you have questions about how, respond to this comment. – Christopher Brown Sep 02 '15 at 21:34
9

Nonono, don't use ="javascript:void(window.open(.
First, it breaks PDF & Excel reports,
and second, it doesn't work in IE11 and possible also < 11.
Tested it, worked only in Chrome for me.
And third, it's a mess to put it together.

There's a far easier & better solution:
Add &rc:LinkTarget=_blank to your report access URL, like:

https://your-domain.com/ReportServer/Pages/ReportViewer.aspx?%2fJPD%2fPO_Dashboard%2fJuvenile_Profile&rs:Command=Render&rc:LinkTarget=_blank 

and it will open in a new window tab.

Edit:
If you want to make your own display page:

This is how you get all reports:

USE [ReportServer$MSSQL_2008_R2]

SELECT 
     [ItemID]
    ,[Path]
    ,[Name]
    ,[ParentID]
FROM [Catalog]
WHERE Type = 2

And this is how you can display all folders/reports at level x

;WITH CTE AS 
(
    SELECT 
         [ItemID]
        ,[Path]
        ,[Name]
        ,[ParentID]
        ,0 AS lvl
        ,CAST([Name] AS nvarchar(MAX)) AS RecursivePath 
     FROM [Catalog] 
     WHERE [ParentID] IS NULL 


     UNION ALL 

     SELECT 
         [Catalog].[ItemID]
        ,[Catalog].[Path]
        ,[Catalog].[Name]
        ,[Catalog].[ParentID] 
        ,cte.lvl +1 AS lvl
        ,CAST(cte.RecursivePath + '/' + [Catalog].[Name] AS nvarchar(MAX)) AS RecursivePath 
     FROM CTE 
     INNER JOIN [Catalog]
        ON [Catalog].ParentID = CTE.ItemID 



) 

SELECT * FROM CTE 
WHERE lvl = 1 
ORDER BY lvl, Path 

If you only want the folders:

WHERE Type = 1

If you only want the data-sources:

WHERE Type = 5
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
  • @Timbo: You locate the access URL when you open a brower and go to http://your-domain.com/ReportServer or locally/intranet with http://machine-name/ReportServer. You can also read all the links from the reportserver database. If your reportserver has a non-standart instance-name, e.g. MSSQL_2008_R2, that becomes: http://localhost/ReportServer_MSSQL_2008_R2. In RS 2005, that was ReportServer$MSSQL_2005 by the way, notice the change from $ to _. – Stefan Steiger Oct 17 '14 at 02:16
4

If you are wanting to link to an external URL and want the links to work both within the report viewer and if you export to Excel for example, I use the following expression.

=IIF(
  Globals!RenderFormat.Name = "RPL",
 "javascript:void(window.open('http://www.domain.com/page/" & Fields!Page_ID.Value & "','_blank'))",
  "http://www.domain.com/page/" & Fields!Page_ID.Value
)

It will use the JavaScript if viewing from within the report in the browser and standard linking otherwise.

Danny Cullen
  • 1,782
  • 5
  • 30
  • 47
0

Here is what I had used; it will open the ChildReport in a new tab, with a parameter voucher_id and its value passed from a dataset.

="javascript:void window.open(" &"'"& Globals!ReportServerUrl &"/Pages/ReportViewer.aspx?"&Globals!ReportFolder &"/JournalVoucher&voucher_id="&Fields!account_voucher_id.Value &" ','_blank')"
rjose
  • 557
  • 5
  • 13