Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a custom code function only once on a reporting services report?

I need to execute a custom code function when the report first loads, and I need it to only run once. Where do I put it?

like image 658
Nathan DeWitt Avatar asked Jan 15 '10 16:01

Nathan DeWitt


People also ask

How do you call a function in SSRS?

To call table-valued function in a SSRS, we can use two ways: 1. Select Query Type as Text in Dataset Properties, then type query with select statement. Please refer to this similar thread: How to use a table- valued function as a datasource for SSRS report?.

How do I create a custom code in report Builder?

To add embedded code to a report In Design view, right-click the design surface outside the border of the report and click Report Properties. Click Code. In Custom code, type the code. Errors in the code produce warnings when the report runs.


1 Answers

I'm not sure how the best way to do this is. I don't think you get any events to hook in to, but you could fudge it. For example, have the header call a function to set the title, and as a by-product call your custom code function once:

Public Dim ReportTitle As String = ""

Public Function GetTitleAndDoSomethingElse As String
    If (ReportTitle = "") Then
        ReportTitle = "My Report Title"
        ' Do your stuff that runs once here
    End If
    Return ReportTitle
End Function

Then in your report header have a text box that is set to:

=Code.GetTitleAndDoSomethingElse

Ugly, but should do the trick.

like image 153
Chris Latta Avatar answered Nov 04 '22 22:11

Chris Latta