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 Section 6.9.) are available.
Besides the basic arithmetic operators you can use the following 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 0.5 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()}. The today object provides the following functions
firstDay | Sets the calendar object to midnight at the first day of the current month |
lastDay | Sets the object to the last second of the last day of the current month |
addDays | Adds the number of days given as argument to the current date (the argument can be negative to subtract days) |
addMonths | Adds the specified number of months to the current date (the argument can be negative to subtract days) |
addYears | Adds the specified number of years to the current date (the argument can be negative to subtract days) |
setDay | Sets the calendar to a specific day |
setMonth | Sets the calendar to a specific month |
setYear | Sets the calendar to a specific year |
clearTime | Clears the time field, that is, the time is set to midnight |
addHours | Adds the specified number of hours to the current date (the argument can be negative to subtract days) |
addMinutes | Adds the specified number of minutes to the current date (the argument can be negative to subtract days) |
addSeconds | Adds the specified number of seconds to the current date (the argument can be negative to subtract days) |
setHours | Sets the hour field |
setMinutes | Sets the minutes field |
setSeconds | Sets the seconds field |
format | This function formats the date according to a specified mask. This may be necessary if the underlying datatype is not a date type but a text type (see Appendix C. for further information). |