1

JasperReport question: I have table with user data and % value of completed test. How to display the String message of value if it is in certain Number range.

Values between 0 and 59 = `Try again`
Values more than 59 = `Doing great`

I used for

Parameter1 $P{Value 1}
Class: java.lang.Long
Expression: $F{percentage}<59.00
Parameter1 $P{Value 2}
Class: java.lang.Long
Expression: $F{percentage}>59.01

Created Detail [Text Field] with following Expression:

IF($P{Value 1},`Try again`,`Doing great`)

Report State:

Value 1 cannot be resolved to a variable.

Alex K
  • 22,315
  • 19
  • 108
  • 236

1 Answers1

0

You do not need variables for this instead just use a ternary operator in you textField expression

$F{percentage}<=59?"Try again":"Doing great".

Your example is not really "between" it's instead just one condition but if you also need "between" you can just nest another ternary operator as in example below (percentage<0)

<textField>
    <reportElement x="0" y="0" width="545" height="20" uuid="43ce93f2-5984-4127-a394-89348e83185b"/>
    <textElement verticalAlignment="Middle"/>
    <textFieldExpression><![CDATA[$F{percentage}<0?"Opps":$F{percentage}<=59?"Try again":"Doing great"]]></textFieldExpression>
</textField>

If you also like to style the textField accordingly you can use conditional style see for example JasperStudio How to use conditional style?

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109