Jump to content
JasperReports 7.0 is now available ×

Alter a field from a SELECT statement before using on report


dburklin
Go to solution Solved by szaharia,

Recommended Posts

Hi all,

I am trying to modify an existing jasper report that is used in our Fishbowl Inventory (Firebird database).

One of the fields returned from the SQL query will return a value that is a alphanumeric part number which may or may not be suffixed with an _R## value (where ## will be a 2 digit number). An example would be 395521_R75 or 594TIMB543_R25, etc.

When we display this value in the final report, we want to truncate the _R## value and only display the 395521, 594TIMB543, etc.

Is there a way to accomplish this with iReports 5.6.0 ?

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Hi all,

So after looking at the suggested answers, it seems like the .split method offered by Sandra is the most point on solution, since the _R## value may or may not exist.

However, the issue I've encountered is that the report is using a $V (variable) instead of a $F (field), so the expression field isn't available.

I tried appending the .split method right onto the $V in the report detail and that didn't work, so I started poking around in the XML and found this:

<variable name="ItemNum" class="java.lang.String">
            <variableExpression><![CDATA[($F{KITPARENTLINE} == null ? "" : "     ") +
($F{PRODUCTNUM} == null || $F{PRODUCTNUM.split("_")[0]}.length() < 1 ?
    "" :
    ($F{CUSTOMERPARTNUM} == null || $F{CUSTOMERPARTNUM}.length() < 1 || !$P{IncludeCustomerPartNumbers} ?
        $F{PRODUCTNUM.split("_")[0]} :
        $F{PRODUCTNUM.split("_")[0]} + " (" + $F{CUSTOMERPARTNUM} + ")"))]]></variableExpression>

The above results in a compilation error, so obviously not the correct approach. Sorry if I'm missing something obvious, I just got thrown into this project and am really unfamiliar with Jasper reports (and report writers in general).

How should I proceed?

Link to comment
Share on other sites

  • Solution

Hello,

At least one of the problems lays within the curly brackets. Expressions like $F{PRODUCTNUM.split("_")[0]} don't represent valid entities in JasperReports. Try to use $F{PRODUCTNUM}.split("_")[0] instead, and see if the issue still occurs.

Also, make sure the PRODUCTNUM field is of type String in order to apply the split() method.

And one last thing: make sure the <variable > tag is properly closed (the </variable> closing tag should be also present in your JRXML file after </variableExpression>).

I hope this helps,

Sanda

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