Reputation: 21
I created a variable to keep a count of all machinery_part_id in a location for my report. This works fine, now I want to add a filter where the machinery_part_id is only counted if they have a quantity > 0.
This is what I had to start with:
Variable Name: PART_COUNT
Variable Class Type: Java.lang.Integer
Calculation Type: Count
Reset Type: Group
Reset Group: LOCATION_ID
Increment Type: None
Variable Expression: $F{MACHINERY_PART_ID}
A field in my report was set up as follows:
Text Field Expression Class: Java.lang.Integer
Evaluation Time: Group
Evaluation Group: LOCATION_ID
Text Field Expression: $V{PART_COUNT}
The new condition is count(machinery_part_id) group by location_id having quantity >0
$F{MACHINERY_PART_ID}
and $F{QUANTITY_SENT}
are both java.lang.double
fields, I tried entering the following in the Variable Expression:
New Double($F{QUANTITY_SENT} > 0.00 ? $F{QUANTITY_SENT}.doubleValue() : 0d)
But it errors out with:
Syntax error, insert ";" to complete BlockStatements
I'm using iReport 3.0.0
Please help, Thanks!
Upvotes: 0
Views: 17614
Reputation: 21
I figured it out:
TEXT FIELD
Text Field Expression Class: Java.lang.Integer
Evaluation Time: Report
Text Field Expression: new Integer($V{PART_COUNT}.intValue())
Found answer here: http://community.jaspersoft.com/questions/525053/cannot-cast-int-integer
Upvotes: 1
Reputation: 21
I figured it out:
VARIABLE
Variable Name: PART_COUNT
Variable Class Type: Java.lang.Double
Calculation Type: Sum
Reset Type: Group
Reset Group: LOCATION_ID
Increment Type: None
Variable Expression: new Double($F{QUANTITY_SENT}.doubleValue() > 0.00 ? 1.0:0.0)
TEXT FIELD
Text Field Expression Class: Java.lang.Double
Evaluation Time: Group
Evaluation Group: LOCATION_ID
Text Field Expression: $V{PART_COUNT}
QUESTION How do I now switch this expression to return an integer??
Thanks for pointing me in the right direction.
Upvotes: 1