Reporting Services Open Link In New Window and Issue with Closing Speechmark Being Converted to HTML

Robin Wilson 11 Reputation points
2023-03-21T09:25:50.3333333+00:00

Hello

I have a report where I want to embed a hyperlink to link to another system and I have tried various approaches but with everything I try either both the starting and ending speechmarks/tick marks/back ticks are automatically converted to the equivalent HTML character code which is then passed to the URL being opened resulting in an error.

An example URL I want to open is:

[http://SERVER/ProMonitor/ilp/meetingscomments/meetings.aspx?academicyearid=2223&pmstudentid=kYtgI8P%2b9GA%3d]

This should be able to be achieved with the following:

javascript:void(window.open('http://SERVER/ProMonitor/ilp/meetingscomments/meetings.aspx?academicyearid=2223&pmstudentid=kYtgI8P%2b9GA%3d'))

However it gets inserted as (from hovering over the link or right-clicking and selecting the copy link option):

javascript:void(window.open('http://SERVER/ProMonitor/ilp/meetingscomments/meetings.aspx?academicyearid=2223&pmstudentid=kYtgI8P%2b9GA%3d%27))

This passes a spurious %27 on the end which then causes the record it should load not to be found.

If I remove the speechmark then the link does not work and nothing happens. If I replace the ' with " then I end up with %22 at the start and the end. If I replace with the back tick then I end up with %60 at the start and the end.

I have tried:

  • Using speeckmarks, tick marks and back ticks
  • Putting the JavaScript part in the expression where the database field contains only the URL
  • Combining the JavaScript and URL into the database field
  • Creating a user defined function in the report code where I can pass the URL to the function

Whatever I try, the output is identical and at least the closing speechmark is converted to its HTML equivalent and passed to the URL

This is an example of a user defined function I created:

Function OpenURL(ByVal URL As String) As String
    Return "javascript:void(window.open('" & URL & "','_blank'))"
End Function

Any help would be appreciated as I feel I have exhausted all options on what I thought would be something really quick and easy.

EDIT

I had a further idea which was to add & to the end of the URL so the pmstudentid parameter ends up intact and then it ends with &%27 however this still errored

Upon further checking, if I disable my internet connection (as the URL results in an instant redirect to an error page on the target application) I end up with the code at the end being translated from:

&pmstudentid=kYtgI8P%2b9GA%3d

To

&pmstudentid=kYtgI8P+9GA=

So it would appear this is actually the real issue although if I copy and paste the URL in Edge it still shows the + as %2B as it should.

I just need it not to convert back and forth between HTML character codes and ASCII codes

This is the reference I used to double check the character encoding:

https://www.w3schools.com/tags/ref_urlencode.ASP

Thanks
Robin

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,807 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Robin Wilson 11 Reputation points
    2023-03-21T10:08:57.3266667+00:00

    I have now found a solution to this which is to use:

    System.Uri.EscapeDataString
    
    

    Used as a user defined function it then becomes:

    Function OpenURL(ByVal URL As String) As String
        Return "javascript:void(window.open('" & System.Uri.EscapeDataString(URL) & "','_blank'))"
    End Function
    
    

    Then in the URL expression on the report you can reference it on the Go To URL expression with:

    =Code.OpenURL(Fields!URL.Value)
    

    This then stops any conversion of HTML character codes and the links all work as intended and originally specified

    1 person found this answer helpful.