Basics of Writing Expressions in JSS
Instead of “Cells”, you will be using Fields & Variables in JasperSoft.
Fields are denoted like this: $F{Field Name}
Variables are denoted like this: $V{Variable Name}
In the Expression Editor, simply double-click on the name of a field or variable, and it will automatically create the syntax for you.
Plain Text in Expressions
Plain text in expressions should always be surrounded by double quotes (just like formulas in Excel)
Equations
Equations with Numeric Fields
Use == for numeric fields
Example
Equations with Text Fields
Use .equals(“ “) for String/Text fields
Example:
Does Not Equal with Numeric Fields
Use != for numeric fields
Example:
Does Not Equal with Text Fields
Use !$F{Field Name}.equals(“ “) for String/Text fields
Example:
Greater/Less Than or Equal To
Use >=
Do not use "==" for Greater/Less Than or Equal To
Example:
Conditional Expressions (i.e. “If, Then” Statements):
Learning how to write an “If Then” expression in JasperSoft studio is an essential building block for creating all sorts of reports. It is very similar to writing “IF()” formulas in Excel, but the syntax is different.
In Excel...
an IF() formula uses the following syntax:
=IF(Condition, Output if True, Output if False)
Example: =IF(B2>A2,"Growth","Decline”)
In JasperSoft Studio...
A conditional expression uses the following syntax:
Condition ? Output if True : Output if False
Example 1:
Example 2:
Example 3:
Syntax: [Condition] ? [Output if True] : [Output if False]
Nested Conditional Expressions
You can nest conditional expressions to create more complex logic statements.
Example 1:
Note: The conditional expression will stop as soon as a condition is met, only moving on to the next condition if the preceding condition is false.
Example 2:
“And” / “Or” Logic
Use && for “And” logic
Example:
Use || for “Or” logic
Example:
The “pipe” character (“ | “) key is located above the return/enter key (hold shift)
Last updated