1. Extending Report Properties by using Expressions
·
Use expressions to calculate values for
parameters, queries, filters, report item properties, group and sort
definitions, text box properties, bookmarks, document maps, dynamic page header
and footer content, images, and dynamic data source definitions.
·
You write expressions in Visual Basic.
·
You start an expression with an equal sign
(=) and then use built-in collections, including dataset fields and parameters,
constants, functions, and operators.
·
In a complex expression, you can reference
multiple dataset fields, parameters, operators, constants, built-in report
functions, Visual Basic runtime library functions, Microsoft .NET Framework
common language runtime (CLR) classes, embedded custom code functions, and functions
from a custom assembly.
·
Several common built-in expressions types:
o
Field
=Fields!LastName.Value
o
Control flow
=Choose(Fields!NameStyle.Value, “Mr”, “Mrs”, “Miss”)
=IIF(Fields!Amount.Value < 0,
“Red”, “Black”)
=Switch(Fields!Amount.Value<
0.90*Fields!Goal.Value, “Red”,
Fields!Amount.Value<Fields!Goal.Value, “Yellow”
, Fields!Amount.Value>=Fields!Goal.Value,
“Green”)
o
Built-in function
=Sum(Fields!Quantity.Value)
=(Rate(Fields!TotPmts.Value, - Fields!Payment.Value,
Fields!PVal.Value)* 12) * 100
·
Using the <Code> Element in a Report
o
Steps
§ Create
the code - Report menu |Report Properties | Code tab | Write the VB Code
§ Use
the code
=Code.GetStockColor(Fields!Quantity.Value, Fields!ReorderPoint.Value)
o
Benefits
The
main benefit of using embedded code in a report is that the code you write at
the report level can be reused in any expression in the report.
2. Extending SSRS with Custom Assemblies - You can use any .NET languages
·
Create a custom assembly with a full blown
Visual Studio and Build the .dll file
·
Deploy the assembly.
o
Copy the assembly file to the application
folders of your SSRS server and the Report Designer.
o
Install your custom assembly in the global
assembly cache (GAC).
·
Optionally, added the appropriate security policy.
·
Add a reference to the assembly in your
report.
·
Use the assembly - using expressions to access
the members of the classes in the assembly
o
You call a static method in your expression by using the
format =Namespace.Class.Method, as this example
shows:
=CustomColors.CustomColor.GetStockColorStatic(Fields!Quantity.Value,Fields!ReorderPoint.Value)
o
For calling instance-based members, you must
instantiate an object of your class type. You add an instance name for a class
by using the Add Or Remove Classes section of the Code
tab in the Report Properties window. Provide a class name and an instance name.
You can then refer to your instance-based members by using the Code keyword
followed by the instance and member name, as in the following example:
=Code.MyCustomColor.GetStockColorInstance(Fields!StockLevel.Value,
Fields!SafetyStockLevel.Value)