Using custom code in SSRS PDF rendering


  • Hi,

    I have a written some custom code ( a simple function to maintain a counter ) in SSRS Report properties.

    Everything works fine when I render the report in Report Viewer, but the custom code is not recognized when I render the report to PDF.

    What is wrong with my code?

    There is no error reported. The custom code is just getting skipped when I render to PDF.

    My custom code is as follows..

    Public Shared Dim iCounter AS Integer = 1

    Public Function IncrementCounter(SomeValue As Boolean) As Boolean

    iCounter = iCounter + 1

    Return SomeValue

    End Function

    Public Function GetCounter() As Integer

    Return iCounter

    End Function

    and my call to the custom code is..


    Thursday, October 17, 2013 12:39 AM


All replies

  • Hi ha_emp,

    From your description, it seems that custom code work well when you preview the report. While it would be skipped when the report is exported to PDF. After testing the custom code in my environment,I find that the custom code will run again when exporting the report, so when we run the report on Report Server and export it to PDF, the custom code will be run twice, the value will be counted twice.

    Based on my research, I find that we can delete the “Shared” in the first row of the custom code to fix this issue. Then the custom code will works well on Report Server.

    If there are any misunderstanding, please elaborate the issue for further investigation.

    Katherine Xiong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

    Sunday, October 20, 2013 12:11 PM
  • Hi,

    Am using the below Custom Code in SSRS to calculate the Median.Everything works fine when i run the report.But when i export it to Excel it shows the Median value as #VALUE!

    How can i solve this ?


    Custom Code:

    Dim values As System.Collections.ArrayList

      Function AddValue(ByVal newValue As Decimal) As Decimal

        If (values Is Nothing) Then

          values = New System.Collections.ArrayList()

        End If


        AddValue = values.Count

      End Function

      Function GetMedian() As Decimal

        Dim count As Integer = values.Count

        If (count > 0) Then


          If count Mod 2 = 1 Then

            GetMedian = values((count - 1) / 2)


            GetMedian = (values((count / 2) - 1) + values((count / 2))) / 2

          End If

        End If

    End Function

    Tuesday, February 04, 2014 4:53 PM