The one stop shop for FIXING your Reporting Service's Issues

Here you can find most of the details regarding the reporting service troubleshooting on different scenarios.

Modifying report variables in Reporting service 2008 R2

Modifying report variables in Reporting service 2008 R2

  • Comments 4

I've seen multiple times where we create a Read / Write Report variable (Group variables are striclty Read only) but not able to find a way to over write the value during the report execution phase.

Here is a way to do it.

Assume that you've created a report variable named "Reportvariable1".

All you need is a piece of custom code.

Public Function SetVariableValue(val as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable)

val.Value = val.Value + 2

End Function

As simple as that. All i'm doing in the function is, take the report variable reference, add 2 to the existing value. That's it.

How you can call this function from your report item?

=Code.SetVariableValue(Variables!Reportvariable1)

This will do the magic. Also note that in the above expression i'm just passing the variable reference and not its value.

You could always make some modifications in the way you want. For example, you want to modify the variable with a customized value and display the same in the textbox, here is what you need to do in the function.

Public Function SetVariableValue(val as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable, newval As Integer) as Integer

val.Value = val.Value + newval

Return Val.Value

End Function

And call it from a textbox,

=Code.SetVariableValue(Variables!Reportvariable1, ReportItems!Textbox1.Value)

Hope this helps!

Selva.

[All the posts are AS-IS with no warranty]

Leave a Comment
  • Please add 7 and 4 and type the answer here:
  • Post
  • hi, i did that on report builder 2.0, but where run that report it gave an error message like this :

    There is an error on line 2 of custom code: [BC30526] propierty 'Value' is 'ReadOnly'.

    ----------------------------

    The definition of the report '' is invalid.

    ----------------------------

    how may I fix it... Help me Please.  edy_almanza@hotmail.com

    tks

  • ReportBuilder 2.0 is only compatible with Reporting Service 2008 and not with Reporting Service 2008 R2. In Reporting service 2008, the variables were READ ONLY and only in Reporting service 2008 R2 and above it is READ, WRITE. So, with ReportBuilder 2.0 this cannot be accomplished.

    Try using ReportBuilder 3.0. But be aware of the fact that the reports you create from Report Builder 3.0 can only be saved on Reporting service 2008 R2 and above. Not on Reporting service 2008.

    HTH,

    Selva.

  • Is there a way to pass in all the variables, and access each one in code?  I have about 15 variables and most of them need to be used in a calculation that happens in the code. Passing a reference to the variables collection and pulling them out in code would be much easier.

    Thanks,

    -Dan

  • @Dan: I don't see anyway of achieving this. We've to rely on passing each paramter individually.

    HTH!

    Selva.

    [All the posts are AS-IS with no warranty]

Page 1 of 1 (4 items)