Custom AJAX function in SSRS report

Zolotoy 221 Reputation points
2020-12-02T15:57:29.517+00:00

I am trying to create a custom function that would do an AJAX call.
Here is the function:
Public Function getImage(ByVal s As String) As String
Dim objHTTP = CreateObject("XMLHttpRequest")
'Dim URL = "http://www.somedomain.com"
'objHTTP.Open("POST", URL)
'objHTTP.send("")
End Function

I call this function in a textbox expression like this:
=Code.getImage("123")

I am getting #error in place of the textbox while running it in the Builder and on the server. If I comment all code in the function then no error.

Any idea how to fix it?

Thanks

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,799 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lukas Yu -MSFT 5,816 Reputation points
    2020-12-07T01:43:57.367+00:00

    Hi,

    Within my experience, this is the only way that I've seen to run a JS code, in the Action function of an item.

    It is a called event in the report. I've not found other way to run the JavaScript in SSRS to work like AJAX function.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Lukas Yu -MSFT 5,816 Reputation points
    2020-12-03T09:15:23.91+00:00

    Hi,

    The AJAX function won't working, because that the custom code is "seen" and processed in SSRS server.

    The browser only received the processed data , and present it.

    For example, I add some code in the report to do some string operation.

    The browser could only receive the processed results see:
    44639-image.png

    It is only a div, no code being passed to the browser.

    AJAX code spinet need to be placed in the script session of the HTML page before the web page being rendered by the browser.

    This is why it is not working in SSRS.

    There is no work around for this , if we only place the code in report Custom Code session.

    Regards,
    Lukas


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    What can I do if my transaction log is full?--- Hot issues November
    How to convert Profiler trace into a SQL Server table -- Hot issues November

    0 comments No comments

  2. Zolotoy 221 Reputation points
    2020-12-03T15:08:48.097+00:00

    So, if I add a function to the ReportViewer.aspx I can use it in my report?

    0 comments No comments

  3. Lukas Yu -MSFT 5,816 Reputation points
    2020-12-04T01:41:26.16+00:00

    Hi,

    It is not suggested to change the official web portal of SSRS. I've not personally tried this, I am afraid this would not work neither.
    Also, even if we add it to the web portal it will change the site behavior for all reports.

    0 comments No comments

  4. Zolotoy 221 Reputation points
    2020-12-04T12:16:14.487+00:00

    I am using this as a textbox expression:
    45284-image.png

    It's not working. The same code only works when it's used in Action.

    Any other idea how to run JS code when a report is running?

    0 comments No comments