Modifying report variables in Reporting service 2008 R2
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]
Comments
Anonymous
July 05, 2012
The comment has been removedAnonymous
July 05, 2012
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.Anonymous
January 03, 2013
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, -DanAnonymous
January 08, 2013
@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]