I have a table in my iReport which naturally has its dataset and I have a variable, that is defined and initialized in the table's dataset return a value (which definitely does within scope of table, not outside it) which I want to use in my main report which holds the table.
How can I do that or any alternatives?
The correct way (jasper report v.5/v.6) to return values from a component using subDataset
is to use variables, define variables in both main report and in subDataset
.
Example (return record count of table to main report)
In main report define a variable
<variable name="TABLE_COUNT" class="java.lang.Integer" resetType="None">
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
In subdataset
define a variable (in example a build in variable will be used $V{REPORT_COUNT}
).
In datasetRun
indicate which subDataset
variable (fromVariable
)
should be return to which main report variable (toVariable
)
<datasetRun subDataset="tableData" uuid="fa5df3de-f4c5-4bfc-8274-bd064e8b81e6">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue fromVariable="REPORT_COUNT" toVariable="TABLE_COUNT"/>
</datasetRun>
The TABLE_COUNT
variable can then be used in the main report, just remember to set correct evaluationTime
Display the value (in main report)
<textField evaluationTime="Report">
<reportElement x="0" y="0" width="100" height="20" uuid="d67ddb3e-b0cc-4fae-9e05-f40eb0f7e059"/>
<textFieldExpression><![CDATA[$V{TABLE_COUNT}]]></textFieldExpression>
</textField>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With