Multiple IF-ELSE

0

Hi,

I have 3 fields with below condtions. Can someone help me with text field expression?

IF "Column 1" equals "A" THEN "Text 1"

OR

IF "Column 2" equals "B" THEN "Text 2"

ELSE

"Column 3"

PP Ocean's picture
Joined: Jan 5 2017 - 2:38am
Last seen: 1 week 3 days ago

1 Answer:

1

In Jasper the supported java IF statement is called a Java Ternary Operator.

Here is the format:      (expression) ? value if true: value if false

Example:

$F{Column1}.equals( "A" ) ? "Text 1"
    : $F{Column2}.equals( "B" ) ? "Text 2"
    : $F{Column3}

In case your ternary gets more complicated here is a link to an article on Java basic operators. This will be helpful if you need to add an AND (&&) or and OR (||) condition.

https://www.tutorialspoint.com/java/java_basic_operators.htm

jgust's picture
196
Joined: Jun 10 2010 - 6:39am
Last seen: 7 hours 9 min ago
Feedback
randomness