0
votes

I want to pass field of table in main report to subreport as a parameter in JasperReports

<jasperReport xmlns ---- >
    <subDataset name="tableDataset" >
    <queryString>
        <![CDATA[{select * from person]]>
    </queryString>
    <field name="ID" class="java.lang.Integer"/>
    </subDataset>
        <title>
            <jr:table >
                <jr:column width="133" >
                    <jr:detailCell >
                        <textField>
                            <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                ---
                --
                </jr:table>
        </title>
        <summary>
                <subreport>
<subreportParameter name="ID">
                <subreportParameterExpression><![CDATA[$F{ID}]]>     </subreportParameterExpression>
            </subreportParameter>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    <subreportExpression><![CDATA["phonemumbers.jasper"]]></subreportExpression>
                </subreport>


        </summary>
</jasperReport>

I passed parameter to subreport as above but getting error as field not found

1

1 Answers

0
votes

The way you are passing the field as parameter from main report to subreport is correct. But you cannot use this parameter directly in subreport. You have to first capture the parameter in subreport and then use it. Add following line to your subreport (just after <import>'s and before <queryString>):

<parameter name="ID" class="java.lang.Integer" isForPrompting="false"/>

Now use it in subreport as:

$P{ID}