Jump to content
Changes to the Jaspersoft community edition download ×

Error Type Mismatch: cannot convert from String to boolean


DawnW

Recommended Posts

Hello All,

I am a newbie to Jaspersoft Studio. I am on version 6.11. I am trying to build a document in the IDE and am getting an error "Error Type Mismatch: cannot convert from string to boolean. This is a variable (for zip code) and is a string. My code in the expression editor of the variable reads:

(LEN(LTRIM($F{COLUMN_7} ) )  > 5)  ? ($F{COLUMN_7}.substring(6,4).equals("0000")) : ( ($F{COLUMN_7}.substring(0,5) ? ($F{COLUMN_7}.substring(0,5) + "-" + $F{COLUMN_7}.substring(6,4)) : $F{COLUMN_7}.substring(0,5))) )

I am trying to replicate the code from Crystal reports into Jaspersoft Studio.

Crystal Reports Code:

if Length (TrimLeft ({cvl_crt_ordrd_schl_ntc.expression:7})) > 5
then
    if Right ({cvl_crt_ordrd_schl_ntc.expression:7}, 4) = "0000"
    then
        Left ({cvl_crt_ordrd_schl_ntc.expression:7}, 5)
    else
        Left({cvl_crt_ordrd_schl_ntc.expression:7}, 5) + "-" + 
        Right ({cvl_crt_ordrd_schl_ntc.expression:7}, 4)
else
    Left({cvl_crt_ordrd_schl_ntc.expression:7},5);
 

Can anyone please guide me to the issue. Expression 7 is also a string. Thanks in advance. Sorry if I missed including something.

Dawn

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Based on the original code, the corresponding Java logic is as follows:

 

($F{COLUMN_7}.trim().length()>5?

("0000".equals($F{COLUMN_7}.substring($F{COLUMN_7}.length()-4 ))?

$F{COLUMN_7}.trim().substring( 0,5 )

:$F{COLUMN_7}.trim().substring( 0,5 )+"-"+$F{COLUMN_7}.substring($F{COLUMN_7}.length()-4))

:$F{COLUMN_7}.trim())

Link to comment
Share on other sites

Explanation of the above code refactoring

Before diving into the code conversion, let's first review what the requirement is with regarding to the original logic. As it appears. the original code was trying to reformat a string consists of five characters on the left and four characters on the right into what looks like a United States Postal Service zip code. The USPS zip code has a format of five digits representing an efficiently designed postal service route followed by a hyphen and four digits that designate a more specific location.Now look at the original logic:  if Length (TrimLeft ({cvl_crt_ordrd_schl_ntc.expression:7})) > 5then    if Right ({cvl_crt_ordrd_schl_ntc.expression:7}, 4) = "0000"    then        Left ({cvl_crt_ordrd_schl_ntc.expression:7}, 5)    else        Left({cvl_crt_ordrd_schl_ntc.expression:7}, 5) + "-" +         Right ({cvl_crt_ordrd_schl_ntc.expression:7}, 4)else    Left({cvl_crt_ordrd_schl_ntc.expression:7},5); Based on the above code at face value, the reformat logic is:1) The string is either has 5 characters on the left or has 5 characters on the left and 4 characters on the right. There are conflicting logic in the code that in one time it implies leading blanks might be in the string (by TrimLeft()) but other times it takes the entire string from the left without trimming (by Left ()). To be on the safe side, let's just use trim() function in our new Java code. * Notice the "greater than five" logic does not guarantee the string size must be at least five characters therefore there are times that the reformated zip code can be from BOTH side of the character string should original string size be less then nine characters.2) If the string does not have more than five characters without leading blanks, just retain the non blank characters as the five digit zip code without formatting;3) If the string has more than five characters, and if the right most of four characters are all zeroes, then just use the leftmost five non blank characters as the five digit zip code;       4) If the string has more than 5 characters, but not all right most of 4 characters are zeroes, then we need to use the leftmost five non blank characters, plus a  hyphen, plus right most of 4 characters to construct the 9 digit zip code.Therefore the corresponding Java logic is as the above.

Link to comment
Share on other sites

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...