Alter a field from a SELECT statement before using on report

0

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 ?

 

dburklin's picture
Joined: Nov 11 2014 - 1:07pm
Last seen: 3 years 7 months ago

5 Answers:

1

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

shertage's picture
1940
Joined: Sep 26 2006 - 8:06pm
Last seen: 3 months 3 days ago
0

Hi,
Like in Excel, we have a pattern in which we can display date etc, in iReports too we have pattern. Click on the field, in the property tab, you will notice pattern. Choose the desired pattern and you can achieve the requirement.

Regards,
KKriplani

kkriplani's picture
847
Joined: Sep 4 2015 - 2:18am
Last seen: 2 weeks 3 days ago
0

Fields are displayed as Text in JasperReports. In the Text component property for the field in question, there should be an "expression" field. Just edit that to show $F{name}.substring(0,$F{name}.length()-4)

hozawa's picture
51118
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 months 1 week ago
0

Hi,

Make sure the field value is not null, then use a split("_") method for this:

($F{field}.split("_")[0])

I hope this helps,

Sanda

shertage's picture
1940
Joined: Sep 26 2006 - 8:06pm
Last seen: 3 months 3 days ago
0

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?

dburklin's picture
Joined: Nov 11 2014 - 1:07pm
Last seen: 3 years 7 months ago
Feedback
randomness