hahagal Posted July 11, 2011 Share Posted July 11, 2011 Hi,I have one VARIABLE1_COUNT and VARIABLE2_COUNT. I would need to reset this 2 variable to 0 when it reached the grouper footer so that it will be resetted to 0 when the new group starts. I did the following and still doesn't seem to be reseted correctly. I have set it the followings respectively for the 2 variables:Variable Class: java.lang.IntegerCalculation: CountReset type: GroupReset group: <The group I want to reset>Increment type: NoneVariable Expression: $V{VARIABLE1}Initial Value Expression: new java.lang.Integer(0) I have also set the field which I want to print when expression is $V{VARIABLE1}.equals(new java.lang.Integer(1)) && $V{VARIABLE2}.equals(new java.lang.Integer(1))Apreciate your help here.. Link to comment Share on other sites More sharing options...
jmurray Posted July 11, 2011 Share Posted July 11, 2011 To count the records in each group set a variable like this:Variable Class: java.lang.IntegerCalculation: CountReset type: GroupReset group: <The group's name>Increment type: NoneVariable Expression: new java.lang.Integer(1)Initial Value Expression: new java.lang.Integer(0) Don't worry about the print when expression in the text field, just set the text field expression to $V{<variable name>} and set the type to java.lang.IntegerPost Edited by jmurray at 07/12/2011 01:24 Link to comment Share on other sites More sharing options...
hahagal Posted July 12, 2011 Author Share Posted July 12, 2011 Hi,Thanks for the reply. I have tried your solution. Seems still not working.I have also try printing out the VARIABLE1 and VARIABLE2 value. It is still not setting to 1 for the first record of each new group. Link to comment Share on other sites More sharing options...
jmurray Posted July 12, 2011 Share Posted July 12, 2011 The reason why it didn't work is that my solution contained a typo (due to a copy and paste tragedy). Apologies. Change the zero in the variable expression to a one: Variable Expression: new java.lang.Integer(1) If that doesn't work please post the relevane sections of xml. Link to comment Share on other sites More sharing options...
hahagal Posted July 13, 2011 Author Share Posted July 13, 2011 Hi,I have tried. Still unable to work.Here is the relavant xml portion.2 variables to set count <variable name="IntercoCount" class="java.lang.Integer" resetType="Group" resetGroup="INTERCO" calculation="Count"> <variableExpression><![CDATA[new java.lang.Integer(1)]]></variableExpression> <initialValueExpression><![CDATA[new java.lang.Integer(0)]]></initialValueExpression> </variable> <variable name="CcyCount" class="java.lang.Integer" resetType="Group" resetGroup="INTERCO" calculation="Count"> <variableExpression><![CDATA[new java.lang.Integer(1)]]></variableExpression> <initialValueExpression><![CDATA[new java.lang.Integer(0)]]></initialValueExpression> </variable> textfield to display when above 2 variables is 1 <textField evaluationTime="Auto" isBlankWhenNull="true"> <reportElement x="100" y="0" width="63" height="12"/> <textElement textAlignment="Left"> <font fontName="Arial" size="8"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[( (!$V{IntercoCount}.equals(new Integer(1)) && !$V{CcyCount}.equals(new Integer(1))) ? " " : $V{CTPY_Type_Text} )]]></textFieldExpression> </textField> Link to comment Share on other sites More sharing options...
jmurray Posted July 13, 2011 Share Posted July 13, 2011 hahagalWrote: textfield to display when above 2 variables is 1 <textField evaluationTime="Auto" isBlankWhenNull="true"> <reportElement x="100" y="0" width="63" height="12"/> <textElement textAlignment="Left"> <font fontName="Arial" size="8"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[( (!$V{IntercoCount}.equals(new Integer(1)) && !$V{CcyCount}.equals(new Integer(1))) ? " " : $V{CTPY_Type_Text} )]]></textFieldExpression> </textField> Try this for your conditional statement: <textField evaluationTime="Now" isBlankWhenNull="true"> <reportElement x="100" y="0" width="63" height="12"/> <textElement textAlignment="Left"> <font fontName="Arial" size="8"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[ ( ( $V{IntercoCount}.intValue()==1 && $V{CcyCount}.intValue()==1) ? $V{CTPY_Type_Text} : "" ) ]]></textFieldExpression> </textField> or this alternate method: <textField evaluationTime="Now" isBlankWhenNull="true"> <reportElement x="100" y="0" width="63" height="12"> <printWhenExpression>new java.lang.Boolean( $V{IntercoCount}.intValue()==1 && $V{CcyCount}.intValue()==1 )</printWhenExpression> </reportElement> <textElement textAlignment="Left"> <font fontName="Arial" size="8"/> </textElement> <textFieldExpression class="java.lang.String"> <![CDATA[ $V{CTPY_Type_Text} ]]> </textFieldExpression> </textField> Both provide the same result in different ways. The first example uses java to solve the problem, the second uses the text element's prinWhenExpression to control whether the textbox is visible or not.Post Edited by jmurray at 13/07/2011 13:00 Link to comment Share on other sites More sharing options...
hahagal Posted July 13, 2011 Author Share Posted July 13, 2011 Hi,Seems like it still doesn't give me the results. Is there any way to store value to a variable and then compare it with the next record? Then display if it is not the same and hide if its the same. Link to comment Share on other sites More sharing options...
lknueve Posted July 13, 2011 Share Posted July 13, 2011 seems like your Variable Expression: new java.lang.Integer(1)should be Variable Expression: new java.lang.Integer(0)for the variable that you want to reset to zero for each new group - otherwise it would reset to 1 Link to comment Share on other sites More sharing options...
jmurray Posted July 13, 2011 Share Posted July 13, 2011 lknueveWrote: seems like your Variable Expression: new java.lang.Integer(1) should be Variable Expression: new java.lang.Integer(0) for the variable that you want to reset to zero for each new group - otherwise it would reset to 1 Hi lknueve, that isn't correct. The value that you want the cariable to reset to is contained in the Inital Value Expression. When the variable type is defined as Count then it increments away from the Initial Value Expression each time the Variable Expression is not null. You can use any static, non-null value to force the counter variable to increment every time a detail record is filled, or you can get funky with it and reference a field that may contain nulls. In that case the counter will only increment when the field is not null. Link to comment Share on other sites More sharing options...
jmurray Posted July 13, 2011 Share Posted July 13, 2011 hahagalWrote: Hi, Seems like it still doesn't give me the results. Is there any way to store value to a variable and then compare it with the next record? Then display if it is not the same and hide if its the same. It might be time to post your report design and a page of output marked up to show what is going wrong Link to comment Share on other sites More sharing options...
lknueve Posted July 13, 2011 Share Posted July 13, 2011 this is where the lack of good documentation comes into play lol Link to comment Share on other sites More sharing options...
jmurray Posted July 13, 2011 Share Posted July 13, 2011 It's documented in Chapter 6 of the iReport Guide. Link to comment Share on other sites More sharing options...
hahagal Posted July 15, 2011 Author Share Posted July 15, 2011 Hi,Is there any way to store value to a variable and then compare it with the next record? Then display if it is not the same and hide if its the same. If its done this way, I might get the result I wanted. Is the above possible? Link to comment Share on other sites More sharing options...
jmurray Posted July 15, 2011 Share Posted July 15, 2011 The solution to your problem will be very simple, but a resolution will be difficult without your report design and a page of output marked up to show what is going wrong 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