Reputation: 726
I am using Jaspersoft Studio and am trying to set a variable to the value of another variable (well actually, I will need a sum of two variables in another variable)
So I have two variables, A and B. I need to put A in B. Whenever I use a textfield to output A, it works fine. If in the variable B, I put a ($V{A}), and I try to print B, I get a null.
Does anyone have a clue as to why this happens?
Report X contains subreport Y which returns a variable
<returnValue subreportVariable="EXPENDITURES_TOTAL_VAR" toVariable="EXPENDITURES_TOTAL_VAR" incrementerFactoryClass=""/>
(note the same variable name in both reports)
Report X then contains another variable
<variable name="STOTAL_VAR" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$V{EXPENDITURES_TOTAL_VAR}]]></variableExpression>
</variable>
This WORKS:
<textField>
<reportElement x="120" y="1" width="70" height="30" uuid="f0e81b0f-ddd3-4f31-9711-cfdeb64f36b2"/>
<textFieldExpression><![CDATA[$V{EXPENDITURES_TOTAL_VAR}]]></textFieldExpression>
</textField>
This does not:
<textField>
<reportElement x="310" y="1" width="100" height="30" uuid="263973e7-33b1-4343-a76c-3edbe5506d66"/>
<textFieldExpression><![CDATA[$V{STOTAL_VAR}]]></textFieldExpression>
</textField>
Upvotes: 0
Views: 5026
Reputation: 633
As this is one of the first SO hits when searching for Jasper reports and use variable within other variable and this doesn't give any help - maybe this answer here can help others who search for an answer for how to use a variable within another variable in an iReport:
Taken from here: http://www.jasperassistant.com/docs/guide/ch06s08.html, the short answer is:
Yes you can use a variable within another variable within an iReport - but the variable which you want to use in the other variable must be declared first - so the sequence of the variable matters.
Hope this helps someone.
Upvotes: 1