Have any questions?
+44 1234 567 890
Appendix A. Expression Language
A. Expression Language
In many cases ReportServer allows to insert formulas which are interpreted at runtime instead of static values. Such expressions are always initiated by a dollar sign and an opening curly bracket and closed with a closing curly bracket. The actual expression is given within the curly brackets: ${formula/expression}. ReportServer uses the unified expression language (UE) standardized in JSR-245 (https://www.jcp.org/en/jsr/detail?id=245 and http://www.oracle.com/technetwork/java/unifiedel-139263.html).
An expression can be a simple calculation or string function such as ${3 + 5} which would compute the number 8. Depending on the context different objects/replacements (such as the today object in filters, see the User Guide for further information) are available.
Besides the basic arithmetic operators you can use the mathematical functions defined in Table .
List of mathematical functions
math:random() | Returns a random number between 0 and 1 |
math:sin(Double) | Computes the sine function. |
math:cos(Double) | Computes the cosine function. |
math:tan(Double) | Computes the tangent function. |
math:abs(Double) | Returns the absolute value. |
math:ceil(Double) | Returns the smallest double value that is greater or equal to the argument and which is equal to a mathematical integer. |
math:floor(Double) | Returns the largest double value that is less or equal to the argument and which is equal to a mathematical integer. |
math:round(Double) | Returns the rounded number (as an integer). |
math:max(Double, Double) | Returns the greater of the two arguments. |
math:min(Double, Double) | Returns the smaller of the two arguments. |
math:pow(Double, Double) | Returns the first value raised to the power of the second. |
math:log(Double) | Computes the natural logarithm. |
math:exp(Double) | Computes the value e raised to the power of the argument. |
math:sqrt(Double) | Computes the square root of the argument. |
math:signum(Double) | Computes the signum function. |
To work with strings the following functions can be used in addition to the methods provided by the java string object:
sutils:left(String, int) | Returns the first n characters of the string. |
sutils:right(String, int) | Returns the last n characters of the string. |
The ternary operator can be used to define conditional expressions:
Condition ? Expression if condition evaluates to true : Expression
if condition evaluates to false.
Thus the expression ${math:random() < 0.5 ? true : false} returns boolean value which is TRUE if the random number is less than and FALSE otherwise. Thus this expression returns TRUE with probability 50%. Depending on the context various objects can be accessed and methods can be called on these objects. In filters, for example, the object "today" can be used to specify dates. To call a method on an object write ${object.methodname()}. The today object returns the current date. To return the first of the current month you can use the method firstDay and write: ${today.firstDay()}.