问题
In SSRS, is it possible to reference a report variable from a report function?
Below is my report function. Instead of declaring and setting the MaxRFWIDRange in the function, I'd rather reference a report variable with the same name.
Function ValidateRFWIDRange(FromRFW As Integer, ToRFW As Integer) As Boolean
Dim DiffRFW As Integer
Dim MaxRFWIDRange As Integer
MaxRFWIDRange = 10000
DiffRFW = ToRFW - FromRFW
If DiffRFW > MaxRFWIDRange Then
Return False
Else
Return True
End if
End Function
回答1:
It looks like you can do this.
I tested this by adding a variable TestVariable
to a report, then adding the following custom code:
Function TestVariableFunctionality(var as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable) As String
Return var.Value
End Function
I called the function from a textbox like so:
=Code.TestVariableFunctionality(Variables!TestVariable)
This outputs the variable's value in the textbox as a string.
You must declare the full namespace as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable
, because Variable
alone is not defined. See below for more info.
Accessing variable in SSRS function
From an MSDN blog:
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.
来源:https://stackoverflow.com/questions/40644956/ssrs-reference-report-variable-from-report-function