title: JasperReports. Using value from parent json in child table
body: <p>JasperReports generate null to table cell if this value is not defined in table scope, but defined globally.</p>
  
  <p>At the top of the report I have defined variables:</p>
  
  <pre><code>&lt;subDataset name="Dataset1" uuid="c145c0b0-641e-4a32-8e07-265189715ef9"&gt;
      &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="data\JSONDdapterNew.xml"/&gt;
      &lt;queryString language="json"&gt;
          &lt;![CDATA[]]&gt;
      &lt;/queryString&gt;
      &lt;field name="groupName" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[groupName]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="elementName" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[elementName]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="elementValue" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[elementValue]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
  &lt;/subDataset&gt;
  </code></pre>
  
  <p>Then I pass they to the Jasper table (markup simplified without dropping sense):</p>
  
  <pre><code>&lt;jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"&gt;
      &lt;datasetRun subDataset="Dataset1" uuid="db1f69ee-c0db-4ece-aacb-a181465bdc79"&gt;
          &lt;dataSourceExpression&gt;&lt;![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("elements")]]&gt;&lt;/dataSourceExpression&gt;
      &lt;/datasetRun&gt;
      &lt;jr:column width="220" uuid="09e23518-5d7f-45d9-9a22-c4b537f0d83f"&gt;
          &lt;jr:detailCell style="Table 2_TD" height="18"&gt;
              &lt;textField isStretchWithOverflow="true"&gt;
                  &lt;reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="220" height="18" uuid="4d0b54e7-584e-4cc9-86f2-59d72b600f1b"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="5"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{groupName}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/jr:detailCell&gt;
      &lt;/jr:column&gt;
      &lt;jr:column width="220" uuid="09e23518-5d7f-45d9-9a22-c4b537f0d83f"&gt;
          &lt;jr:detailCell style="Table 2_TD" height="18"&gt;
              &lt;textField isStretchWithOverflow="true"&gt;
                  &lt;reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="220" height="18" uuid="4d0b54e7-584e-4cc9-86f2-59d72b600f1b"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="5"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{elementName}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/jr:detailCell&gt;
      &lt;/jr:column&gt;
      &lt;jr:column width="220" uuid="09e23518-5d7f-45d9-9a22-c4b537f0d83f"&gt;
          &lt;jr:detailCell style="Table 2_TD" height="18"&gt;
              &lt;property name="com.jaspersoft.studio.unit.width" value="px"/&gt;
              &lt;textField isStretchWithOverflow="true"&gt;
                  &lt;reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="220" height="18" uuid="4d0b54e7-584e-4cc9-86f2-59d72b600f1b"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="5"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{elementValue}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/jr:detailCell&gt;
      &lt;/jr:column&gt;
  &lt;/jr:table&gt;
  </code></pre>
  
  <p>Example for input json:</p>
  
  <pre><code>[
      {
          "groupName" : "Group1",
          "elements" : [
              {
                  "elementName" : "el11",
                  "elementValue" : "evl1"
              },
              {
                  "elementName" : "el12",
                  "elementValue" : "evl2"
              }
          ]
      },
      {
          "groupName" : "Group2",
          "elements" : [
              {
                  "elementName" : "el21",
                  "elementValue" : "ev21"
              },
              {
                  "elementName" : "el22",
                  "elementValue" : "ev22"
              }
          ]
      }   
  ]
  </code></pre>
  
  <p>As result I see values for <code>elementName</code> and <code>elementValue</code>, but for <code>groupName</code> I see <code>null</code>. I want to see something like that:</p>
  
  <p>Group1 | el11 | ev11 |</p>
  
  <p>Group1 | el12 | ev12 |</p>
  
  <p>Group2 | el21 | ev21 |</p>
  
  <p>Group2 | el22 | ev22 |</p>