Display subreport within a list using list field as parameter

251 views Asked by At

I am trying to display a subreport within a list in a main report. Using Field X from the list to populate the corresponding information within the subreport. So Field X will act as some kind of "Primary Reference" in the Subreport.

I have an XML datasource and the subreport uses a different xpath from the subreport.

I got the list to display properly but the subreport is blank.

Here is the Main report

<?xml version="1.0" encoding="UTF-8"?>
<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="PickupDrop" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <subDataset name="ShipmentPerStopList">
        <parameter name="ShipmentID" class="java.lang.String">
            <parameterDescription><![CDATA[child::text()]]></parameterDescription>
            <defaultValueExpression><![CDATA[]]></defaultValueExpression>
        </parameter>
        <queryString language="xPath">
            <![CDATA[/Main/Load/Plan/Events/Event[@sequenceNum]/Shipments/ReferenceNumbers/ReferenceNumber]]>
        </queryString>
        <field name="ReferenceNumber" class="java.lang.String">
            <fieldDescription><![CDATA[child::text()]]></fieldDescription>
        </field>
        <field name="isPrimary" class="java.lang.String">
            <fieldDescription><![CDATA[@isPrimary]]></fieldDescription>
        </field>
        <field name="type" class="java.lang.String">
            <fieldDescription><![CDATA[@type]]></fieldDescription>
        </field>
        <variable name="varReferenceNumber" class="java.lang.String">
            <variableExpression><![CDATA[$F{ReferenceNumber}+" ("+ $F{type} +")"]]></variableExpression>
        </variable>
        <variable name="varShipID" class="java.lang.String">
            <variableExpression><![CDATA[$F{ReferenceNumber}]]></variableExpression>
        </variable>
    </subDataset>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <parameterDescription><![CDATA[]]></parameterDescription>
        <defaultValueExpression><![CDATA[""]]></defaultValueExpression>
    </parameter>
    <parameter name="EventSequence" class="java.lang.String" isForPrompting="false">
        <parameterDescription><![CDATA[/Main/Load/Plan/Events/Event/@sequenceNum]]></parameterDescription>
    </parameter>
    <parameter name="ShipmentID" class="java.lang.String" isForPrompting="false">
        <property name="net.sf.jasperreports.engine.JasperReport" value=""/>
    </parameter>
    <queryString language="xPath">
        <![CDATA[/Main/Load/Plan/Events/Event]]>
    </queryString>
    <field name="SequenceNum" class="java.lang.String">
        <fieldDescription><![CDATA[@sequenceNum]]></fieldDescription>
    </field>
    <field name="Type" class="java.lang.String">
        <fieldDescription><![CDATA[@type]]></fieldDescription>
    </field>
    <field name="dateEarliest" class="java.lang.String">
        <fieldDescription><![CDATA[Dates/Date[@type="earliest"]]]></fieldDescription>
    </field>
    <field name="dateLatest" class="java.lang.String">
        <fieldDescription><![CDATA[Dates/Date[@type="latest"]]]></fieldDescription>
    </field>
    <field name="AddressName" class="java.lang.String">
        <fieldDescription><![CDATA[Address/Name]]></fieldDescription>
    </field>
    <field name="AddressLine1" class="java.lang.String">
        <fieldDescription><![CDATA[Address/AddrLine1]]></fieldDescription>
    </field>
    <field name="AddressLine2" class="java.lang.String">
        <fieldDescription><![CDATA[Address/AddrLine2]]></fieldDescription>
    </field>
    <field name="AddressCity" class="java.lang.String">
        <fieldDescription><![CDATA[Address/City]]></fieldDescription>
    </field>
    <field name="AddressState" class="java.lang.String">
        <fieldDescription><![CDATA[Address/StateProvince]]></fieldDescription>
    </field>
    <field name="AddressZIP" class="java.lang.String">
        <fieldDescription><![CDATA[Address/PostalCode]]></fieldDescription>
    </field>
    <field name="AddressCountry" class="java.lang.String">
        <fieldDescription><![CDATA[Address/Country]]></fieldDescription>
    </field>
    <field name="LocationComments" class="java.lang.String">
        <fieldDescription><![CDATA[Address/Comments]]></fieldDescription>
    </field>
    <variable name="EventDates" class="java.lang.String">
        <variableExpression><![CDATA[$F{dateEarliest} + " - " +$F{dateLatest}]]></variableExpression>
    </variable>
    <variable name="CompleteAddress" class="java.lang.String">
        <variableExpression><![CDATA[( $F{AddressName} !=null ? $F{AddressName} : "" )
+", "+($F{AddressLine1} !=null ? $F{AddressLine1} : "")
+" "+ ($F{AddressLine2} !=null ? $F{AddressLine2} :"")
+" "+ $F{AddressCity}
+", "+ $F{AddressState}
+", "+$F{AddressZIP}
+", "+ ($F{AddressCountry} !=null ? $F{AddressCountry} : "")]]></variableExpression>
    </variable>
    <variable name="EventSequence" class="java.lang.String">
        <variableExpression><![CDATA[$F{SequenceNum}]]></variableExpression>
    </variable>
    <detail>
        <band height="292" splitType="Stretch">
            <componentElement>
                <reportElement mode="Transparent" x="0" y="71" width="548" height="131" isRemoveLineWhenBlank="true"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                    <datasetRun subDataset="ShipmentPerStopList">
                        <datasetParameter name="ShipmentID">
                            <datasetParameterExpression><![CDATA[$P{ShipmentID}]]></datasetParameterExpression>
                        </datasetParameter>
                        <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/Event/Shipments/ReferenceNumbers/ReferenceNumber")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="131" width="548">
                        <textField>
                            <reportElement x="7" y="0" width="196" height="20"/>
                            <textElement/>
                            <textFieldExpression class="java.lang.String"><![CDATA[$V{varReferenceNumber}]]></textFieldExpression>
                        </textField>
                        <subreport isUsingCache="false">
                            <reportElement x="7" y="26" width="465" height="84" isRemoveLineWhenBlank="true"/>
                            <subreportParameter name="ShipmentID">
                                <subreportParameterExpression><![CDATA[$V{varShipID}]]></subreportParameterExpression>
                            </subreportParameter>
                            <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/Main/Load/Shipments/Shipment[ReferenceNumbers/ReferenceNumber[text()='"+$P{ShipmentID}+"']]")]]></dataSourceExpression>
                            <subreportExpression class="java.lang.String"><![CDATA["StopShipmentReferences.jrxml"]]></subreportExpression>
                        </subreport>
                    </jr:listContents>
                </jr:list>
            </componentElement>
            <textField>
                <reportElement x="45" y="0" width="49" height="16" forecolor="#FFFFFF"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[($F{Type})]]></textFieldExpression>
            </textField>
            <rectangle>
                <reportElement x="0" y="14" width="555" height="18" forecolor="#000000" backcolor="#CCCCCC"/>
            </rectangle>
            <textField>
                <reportElement x="2" y="16" width="286" height="16"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{EventDates}]]></textFieldExpression>
            </textField>
            <rectangle>
                <reportElement x="0" y="32" width="555" height="39" forecolor="#000000" backcolor="#CCCCCC"/>
            </rectangle>
            <textField isBlankWhenNull="true">
                <reportElement x="4" y="33" width="546" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{CompleteAddress} + "\n"]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement mode="Opaque" x="0" y="0" width="107" height="14" forecolor="#FFFFFF" backcolor="#000000"/>
                <textElement verticalAlignment="Middle">
                    <font isBold="false"/>
                </textElement>
                <text><![CDATA[Stop]]></text>
            </staticText>
            <textField>
                <reportElement x="26" y="1" width="25" height="13" forecolor="#FFFFFF"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{SequenceNum}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="51" y="0" width="43" height="13" forecolor="#FFFFFF"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{Type}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="4" y="53" width="544" height="18" isRemoveLineWhenBlank="true">
                    <printWhenExpression><![CDATA[$F{LocationComments}!= null]]></printWhenExpression>
                </reportElement>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{LocationComments}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
`

Subreport:

<?xml version="1.0" encoding="UTF-8"?>
<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="StopShipmentReferences" language="groovy" pageWidth="555" pageHeight="802" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <parameter name="ShipmentID" class="java.lang.String" isForPrompting="false">
        <parameterDescription><![CDATA[]]></parameterDescription>
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <queryString language="XPath">
        <![CDATA[/Main/Load/Shipments/Shipment[ReferenceNumbers/ReferenceNumber[text()='$V{ShipmentID}']]]]>
    </queryString>
    <field name="PONumber" class="java.lang.String">
        <fieldDescription><![CDATA[ReferenceNumbers/ReferenceNumber[@type='PO Number']/text()]]></fieldDescription>
    </field>
    <field name="BOL" class="java.lang.String">
        <fieldDescription><![CDATA[ReferenceNumbers/ReferenceNumber[@type='BOL']/text()]]></fieldDescription>
    </field>
    <field name="ContainerNumber" class="java.lang.String">
        <fieldDescription><![CDATA[ReferenceNumbers/ReferenceNumber[@type='Container_Number']/text()]]></fieldDescription>
    </field>
    <field name="ShipmentWeight" class="java.lang.String">
        <fieldDescription><![CDATA[Weights/Weight[@type='actual']/text()]]></fieldDescription>
    </field>
    <field name="weightUOM" class="java.lang.String">
        <fieldDescription><![CDATA[Weights/Weight[@type="actual"]/@uom]]></fieldDescription>
    </field>
    <field name="QuantityUOM" class="java.lang.String">
        <fieldDescription><![CDATA[Quantities/Quantity/@uom]]></fieldDescription>
    </field>
    <field name="ShipmentQuantity" class="java.lang.String">
        <fieldDescription><![CDATA[Quantities/Quantity/text()]]></fieldDescription>
    </field>
    <field name="SCAC" class="java.lang.String">
        <fieldDescription><![CDATA[ReferenceNumbers/ReferenceNumber[@type='SCAC']/text()]]></fieldDescription>
    </field>
    <field name="ShipID" class="java.lang.String">
        <fieldDescription><![CDATA[ReferenceNumbers/ReferenceNumber[@isPrimary='true']/text()]]></fieldDescription>
    </field>
    <field name="ShipUnitWeight" class="java.lang.String">
        <fieldDescription><![CDATA[ItemGroups/ItemGroup/Weights/Weight[@type="actual"]/text()]]></fieldDescription>
    </field>
    <variable name="ShipmentID" class="java.lang.String">
        <variableExpression><![CDATA[]]></variableExpression>
    </variable>
    <variable name="varShipWeight" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA[$F{ShipUnitWeight}!=null && $F{ShipUnitWeight}!= "0.0" ? ($F{ShipUnitWeight} +" "+ $F{weightUOM}): $F{ShipmentWeight}+" "+$F{weightUOM}]]></variableExpression>
    </variable>
    <variable name="varPONumber" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA[$F{PONumber} +" (PO Number)"]]></variableExpression>
    </variable>
    <variable name="varContainerNumber" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA[$F{ContainerNumber}!= null? $F{ContainerNumber} + " (Container Number)" : " "]]></variableExpression>
    </variable>
    <variable name="varSCAC" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA[$F{SCAC}]]></variableExpression>
    </variable>
    <variable name="varQuantity" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA[$F{ShipmentQuantity} != null ? $F{ShipmentQuantity}+" "+$F{QuantityUOM} : " "]]></variableExpression>
    </variable>
    <variable name="varBOL" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA[$F{BOL} != null ? $F{BOL} +" (BOL)" : " "]]></variableExpression>
    </variable>
    <detail>
        <band height="108" splitType="Stretch">
            <textField evaluationTime="Band" isBlankWhenNull="true">
                <reportElement x="3" y="1" width="244" height="20"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{varShipWeight}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Band" isBlankWhenNull="true">
                <reportElement x="375" y="1" width="151" height="20"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{varQuantity}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Band" isBlankWhenNull="true">
                <reportElement x="3" y="21" width="165" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{varPONumber}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Band" isBlankWhenNull="true">
                <reportElement x="3" y="41" width="165" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{varContainerNumber}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Band" isBlankWhenNull="true">
                <reportElement x="3" y="61" width="165" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{varBOL}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Band" isBlankWhenNull="true">
                <reportElement x="3" y="81" width="165" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$V{varBOL}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
0

There are 0 answers