Jump to content
We've recently updated our Privacy Statement, available here ×

Resetting Initial Value Expression


hahagal

Recommended Posts

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

Calculation: Count

Reset type: Group

Reset group: <The group I want to reset>

Increment type: None

Variable 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

  • Replies 13
  • Created
  • Last Reply

Top Posters In This Topic

To count the records in each group set a variable like this:

Variable Class: java.lang.Integer

Calculation: Count

Reset type: Group

Reset group: <The group's name>

Increment type: None

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



Post Edited by jmurray at 07/12/2011 01:24
Link to comment
Share on other sites

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

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

hahagal
Wrote:
 

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

lknueve
Wrote:
 

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

hahagal
Wrote:
 

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

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

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