Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return value from table's DataSource to main report in iReport?

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?

like image 921
yayayokoho3 Avatar asked May 01 '12 06:05

yayayokoho3


1 Answers

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)

  1. In main report define a variable

    <variable name="TABLE_COUNT" class="java.lang.Integer" resetType="None">
       <initialValueExpression><![CDATA[0]]></initialValueExpression>
    </variable>
    
  2. In subdataset define a variable (in example a build in variable will be used $V{REPORT_COUNT}).

  3. 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>
like image 97
Petter Friberg Avatar answered Oct 10 '22 10:10

Petter Friberg