dburklin Posted March 10, 2016 Share Posted March 10, 2016 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 More sharing options...
kkriplani Posted March 11, 2016 Share Posted March 11, 2016 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 Link to comment Share on other sites More sharing options...
hozawa Posted March 11, 2016 Share Posted March 11, 2016 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) Link to comment Share on other sites More sharing options...
szaharia Posted March 11, 2016 Share Posted March 11, 2016 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 Link to comment Share on other sites More sharing options...
dburklin Posted March 14, 2016 Author Share Posted March 14, 2016 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 More sharing options...
Solution szaharia Posted March 16, 2016 Solution Share Posted March 16, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now