mmedici Posted November 10, 2010 Share Posted November 10, 2010 I have a variable expression which is subtracting two numbers. I want to modify this report so that it only displays the negative answer. meaning I only want to see the resulting answers which are a negative number. Anyone have any suggestions? Code: <variable name="STK_RTOT" class="java.lang.String" resetType="Group" incrementType="Group" incrementGroup="SOHNUM_0" resetGroup="ITMREF_0" calculation="Sum"> <variableExpression><![CDATA[$F{TOTSTK} - $V{STK_CNT}]]></variableExpression> <initialValueExpression><![CDATA[0]]></initialValueExpression> </variable> Link to comment Share on other sites More sharing options...
darth_fader Posted November 10, 2010 Share Posted November 10, 2010 Explore using printWhenExpression. This should do the trick. printWhenExpression:Definition of a Boolean expression that will determine if the element or the band should be printed or not. Link to comment Share on other sites More sharing options...
mmedici Posted November 11, 2010 Author Share Posted November 11, 2010 so i have looked into it, but i am not a programmer and i have no idea what i am doing.Can someone please provide me with some guidance on how to use it.or is there a way to just manipulate that existing code? Link to comment Share on other sites More sharing options...
mmedici Posted November 12, 2010 Author Share Posted November 12, 2010 wanted to follow up to see if anyone had any suggstions on this Link to comment Share on other sites More sharing options...
chgsd Posted November 13, 2010 Share Posted November 13, 2010 If I understood you correctly, you want to do something like what I have put in the code below.It should print the number if less than 0, otherwise print ""It uses the short if this?then do this:else do this syntax.I hope that helps.Code:($F{TOTSTK} - $V{STK_CNT} < 0)?$F{TOTSTK} - $V{STK_CNT}:"" Link to comment Share on other sites More sharing options...
mmedici Posted November 15, 2010 Author Share Posted November 15, 2010 When i try and insert that printwhenexpression i get an error of: Error loading the report template:Org.xml.sax.SAXParseException:cvc-complex-type.2.4.a: Invalid content was found starting with the element 'printWhenExpression'. One '{variableExpression, initialValueExpression}' is expected. any thoughts on this error? Link to comment Share on other sites More sharing options...
chgsd Posted November 15, 2010 Share Posted November 15, 2010 What I was recommending was actually bypassing the printWhenExpression. Please review the code below and see if it works. There isn't anything wrong with printWhenExpression, but because of your mentioning your beginning with this, I meant to give you a string to replace your existing string with.printWhenExpression needs to return evaluate to true/false, and is like a switch that enables printing or not printing. What I gave to you always prints, just it prints nothing if the result is 0 or greater.I hope this helps.Cheers,CHgsdCode: <variable name="STK_RTOT" class="java.lang.String" resetType="Group" incrementType="Group" incrementGroup="SOHNUM_0" resetGroup="ITMREF_0" calculation="Sum"> <variableExpression><![CDATA[($F{TOTSTK} - $V{STK_CNT} < 0)?$F{TOTSTK} - $V{STK_CNT}:""]]></variableExpression> <initialValueExpression><![CDATA[0]]></initialValueExpression> </variable> Link to comment Share on other sites More sharing options...
mmedici Posted November 15, 2010 Author Share Posted November 15, 2010 This worked really well. However, is there a way for it not to show the rows that are positive? meaning, it ran the report and shows an anser for all the items which are negative, and deosn't show anything if it is positive. However it shows the row, is there a way to remove the row or item if the answer is negative? Link to comment Share on other sites More sharing options...
mmedici Posted November 16, 2010 Author Share Posted November 16, 2010 Anyone have any other suggestions on this? i think a printwhenexpression may be the answer i am looking for, problem is when i google how to use the expression i don't see much information out there on it.Anyone know how to make that expression work in this instance? Link to comment Share on other sites More sharing options...
mmedici Posted November 16, 2010 Author Share Posted November 16, 2010 let me know if it would do anyone any good to post the entire report code out here as well. i can do that too if need be Link to comment Share on other sites More sharing options...
chgsd Posted November 16, 2010 Share Posted November 16, 2010 If it can wait a few hours I can write the block of code for you, having the full report wouldn't hurt, but just the code for the element in question and perhaps surrounding elements would suffice.I can get to this in probably 4-6hours. Link to comment Share on other sites More sharing options...
mmedici Posted November 16, 2010 Author Share Posted November 16, 2010 Link to comment Share on other sites More sharing options...
chgsd Posted November 16, 2010 Share Posted November 16, 2010 I am including below the relevant portion of your jrxml file. This should do what you want by only printing the textField if $V{STK_RTOT} is less than 0. If it evaluates to 0 or greater, the textfield should be absent.Code: <textField> <reportElement x="610" y="1" width="96" height="18"> <printWhenExpression><![CDATA[$V{STK_RTOT}<0]]></printWhenExpression> </reportElement> <textElement textAlignment="Center" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.String"><![CDATA[$V{STK_RTOT}]]></textFieldExpression> </textField> Link to comment Share on other sites More sharing options...
mmedici Posted November 17, 2010 Author Share Posted November 17, 2010 close getting an error message oferror evaluating expression: Source Text: $V{STK_RTOT}<0 Link to comment Share on other sites More sharing options...
chgsd Posted November 17, 2010 Share Posted November 17, 2010 The problem lies not in what I gave you, but what you already had. You are casting that variable as a string, when it is not.Please change the class="java.lang.String" in the block below to something more appropriate, most likely java.math.BigDecimal in your case. I suspect that will solve your problem.Cheers,CHgsdCode: <variable name="STK_RTOT" class="java.lang.String" resetType="Group" incrementType="Group" incrementGroup="SOHNUM_0" resetGroup="ITMREF_0" calculation="Sum"> <variableExpression><![CDATA[$F{TOTSTK} - $V{STK_CNT}]]></variableExpression> <initialValueExpression><![CDATA[0]]></initialValueExpression> </variable> Link to comment Share on other sites More sharing options...
mmedici Posted November 17, 2010 Author Share Posted November 17, 2010 Link to comment Share on other sites More sharing options...
chgsd Posted November 17, 2010 Share Posted November 17, 2010 When you say "item" what do you mean. The textField will not be printed with the block I gave to you.If you mean some parent element you need to use that same printWhenExpression for the given "item". For example if you do not want the detail band printed when that condition is met, put the printWhenExpression in the detail band.Does that make more sense?Cheers,CHgsd Link to comment Share on other sites More sharing options...
mmedici Posted November 17, 2010 Author Share Posted November 17, 2010 Ok, i put the printwhenexpression within the reportelement part of each column and it has made the information disappear which is great. however, it leaves empty rows where that information was. meaning the report comes out 152 pages, with a lot of empty or blank rows. If we consolidated the rows to where there was only text then the report would only take 3 pages or so by the way, thank you again for all of your help. Link to comment Share on other sites More sharing options...
mmedici Posted November 29, 2010 Author Share Posted November 29, 2010 just following up to see if anyone has any idea on how to remove the blank rows. 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