PrintWhen expression and/or condition

 Hi,

due to my lack of Java/Groovy knowledge I have to ask how to create a printwhen expression with a and/or condition.

Example:

$F{Field1}==1 and $F{Field2}!=0

Does someone know the syntax?

pumaking's picture
383
Joined: Mar 10 2008 - 7:45pm
Last seen: 10 years 5 months ago

4 Answers:

Hi,

Make sure that your fields are Integer type becasue otherwise will not work

(($F{Field1}==1 && $F{Field2}!=0) ? Boolean.TRUE : Boolean.FALSE)

Hope this helps,

Regards.

 

augarte's picture
5639
Joined: Jan 27 2010 - 7:20am
Last seen: 2 years 8 months ago

Just a minor addition, I recently had a problem with conditional statements and subreports. i recommend this minor change to  augarte's suggestion:

(($F{Field1}==new Integer(1).intValue() && $F{Field2}!=new Integer(0).intValue()) ? Boolean.TRUE : Boolean.FALSE)

It appears that at least in version 4.1.3 failure to explicitly define a integer value as such can in some circusmstances result in it being treated as a  string value, thereby causing a class cast exception at runtime.

mwatkinson's picture
Joined: Jul 15 2011 - 12:03pm
Last seen: 11 years 10 months ago

 Thanks for your help so far.

The problem is that I have a string and a bigdecimal field. So is this impossible?

pumaking's picture
383
Joined: Mar 10 2008 - 7:45pm
Last seen: 10 years 5 months ago

Hi,

Not sure how could yo do this, maybe this could work:

(($F{Field1}.intValue () ==new Integer(1).intValue() && Integer.parseInt($F{Field2})!=new Integer(0).intValue()) ? Boolean.TRUE : Boolean.FALSE)

In this case I assume that Field1 is BigDecimal and Field2 is string type.

Hope this helps.

Regards.

augarte's picture
5639
Joined: Jan 27 2010 - 7:20am
Last seen: 2 years 8 months ago
Feedback