Jump to content
Changes to the Jaspersoft community edition download ×

if else "and or"


2005 IR Help

Recommended Posts

By: Edward Mann - emann

if else "and or"

2005-10-04 13:30

I have a report that is getting some data from a database. The fields that i have are money fields. However some have 0 as a value and some are blank/null and others actually have a value in them. When the field is blank/null or just have a 0 in them i don't want them to print. I have spent a few hours reading through the mailing lists and other sites, but i just cannot figure out how to write an expression that will report what i want.

 

i want something like this

 

if ($value != "") || ($value != "0") {

print the field

}

Any hints?

 

Thanks.

 

 

 

 

 

By: Wal Millard - walmillard

RE: if else "and or"

2005-10-04 16:59

 

Edward,

 

the "if" statement implemented in ireport/jasper report is the java in-line if.

 

(Condition)?(boolean.TRUE result):(boolean.FALSE result)

 

the ? and the : are the key operators.

 

for the zero amount use something like this

 

$F{myDollar}.doubleValue() == 0?(" "):($F{myDollar})

 

this will print a single space instead of 0.

 

NOTE if you are using a float type you would have to use floatValue() instead of doubleValue().

 

now if you want to combine more than one condition, say for null, you can nest the if statements in either the TRUE or FALSE result.

 

$F{myDollar}.doubleValue() == 0?(" "):$F{myDollar} == null?(" "):$F{myDollar}

 

for a "null" value you should be able to set the check box "blank when null" so the text "null" is not displayed.

 

luck

walmillard

 

 

 

 

By: Edward Mann - emann

RE: if else "and or"

2005-10-04 20:32

walmillard,

 

Thanks for the reply. I did a google on that java in-line if and found some information. Howerever i am still at a loss. I tried what you suggested, howerver the error i am getting when i compile the report is.

"Print When Expression: Incompatible conditional operand types String and Double"

 

I have entered your example the exact way you have it typed, just changing out the Field value with my own. Which my field value is of a type java.lang.Double

$F{Total_Exp_PSF}.doubleValue() == 0?(" "):($F{Total_Exp_PSF})

I am putting this in Text.field.expression is that right?

 

I have set it to not print when null. Now i just need to keep it from printing when the value is just 0.

 

I am new to all this, and i appreciate the help very much.

 

Thanks.

 

 

 

 

By: JenJo - jenjo

RE: if else "and or"

2005-12-06 08:57

Hi

 

Just wanted to check, did u ever solve this problem?

As i am getting the same error and not sure where else to put it if not in a text. field.expression?

 

Thanks

 

 

 

 

By: PhreddNet - phreddnet

RE: if else "and or"

2005-12-06 10:05

The problem with the "if" statement is that it returns two different value type, one String the other Double. Add ".asString()" to the end of the Double value to get the same object types. (or convert the String to a Double if you are brave enough).

 

A better solution would be to set the "Print when expression" value for the field to the following "($F{myDollar}!= null)&&($F{myDollar} != 0)".

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...