title: How to pass value/variabile from subreport to main report?
body: <p>I want to simply return a value from sub report to main report, but always shows <code>null</code> when the report is executed. Using iReport 5.1.0.</p>
  
  <h1>Main report</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report4" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ce028d85-f7e8-4abd-ad6b-e3b2ba04d14e"&gt;
  &lt;property name="ireport.zoom" value="1.0"/&gt;
  &lt;property name="ireport.x" value="0"/&gt;
  &lt;property name="ireport.y" value="0"/&gt;
  &lt;parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"&gt;
      &lt;defaultValueExpression&gt;&lt;![CDATA["C:\\Users\\DellXFR\\"]]&gt;&lt;/defaultValueExpression&gt;
  &lt;/parameter&gt;
  &lt;variable name="z" class="java.lang.Integer" calculation="System"&gt;
      &lt;variableExpression&gt;&lt;![CDATA[8]]&gt;&lt;/variableExpression&gt;
  &lt;/variable&gt;
  &lt;background&gt;
      &lt;band splitType="Stretch"/&gt;
  &lt;/background&gt;
  &lt;title&gt;
      &lt;band height="79" splitType="Stretch"/&gt;
  &lt;/title&gt;
  &lt;detail&gt;
      &lt;band height="125" splitType="Stretch"&gt;
          &lt;subreport&gt;
              &lt;reportElement uuid="0c501730-d98a-4982-9953-2939f127ad9e" x="40" y="10" width="200" height="100"/&gt;
              &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
              &lt;returnValue subreportVariable="x" toVariable="z"/&gt;
              &lt;subreportExpression&gt;&lt;![CDATA[$P{SUBREPORT_DIR} + "report4_subreport1.jasper"]]&gt;&lt;/subreportExpression&gt;
          &lt;/subreport&gt;
          &lt;textField evaluationTime="Band"&gt;
              &lt;reportElement uuid="9020a8d9-5799-4907-b8a3-704f41ffdcc0" x="399" y="73" width="100" height="20"/&gt;
              &lt;textElement/&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$V{z}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
      &lt;/band&gt;
  &lt;/detail&gt;
  &lt;summary&gt;
      &lt;band height="42" splitType="Stretch"/&gt;
  &lt;/summary&gt;
    &lt;/jasperReport&gt;
  </code></pre>
  
  <h1>Subreport</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report4_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="78290b3a-34c2-496e-86ff-e213ca2c1039"&gt;
  &lt;property name="ireport.zoom" value="1.0"/&gt;
  &lt;property name="ireport.x" value="0"/&gt;
  &lt;property name="ireport.y" value="0"/&gt;
  &lt;queryString language="SQL"&gt;
      &lt;![CDATA[select * from ot;]]&gt;
  &lt;/queryString&gt;
  &lt;field name="salscheme_id" class="java.lang.String"&gt;
      &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
  &lt;/field&gt;
  &lt;field name="ot_amount" class="java.lang.Double"&gt;
      &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
  &lt;/field&gt;
  &lt;variable name="x" class="java.lang.Integer"&gt;
      &lt;variableExpression&gt;&lt;![CDATA[1]]&gt;&lt;/variableExpression&gt;
  &lt;/variable&gt;
  &lt;group name="salscheme_id"&gt;
      &lt;groupExpression&gt;&lt;![CDATA[$F{salscheme_id}]]&gt;&lt;/groupExpression&gt;
  &lt;/group&gt;
  &lt;background&gt;
      &lt;band splitType="Stretch"/&gt;
  &lt;/background&gt;
  &lt;detail&gt;
      &lt;band height="125" splitType="Stretch"/&gt;
  &lt;/detail&gt;
      &lt;/jasperReport&gt;
  </code></pre>