So I'm editing a old Jasper document we have in our system. The document presents a packing slip based on a XML file.
Now we would like to do the following:
If there is more than 1 article line with the same article we would like to add those up / combine them into one line.
I'm not very familiar with iReport and I only made some small field linking changes.
When I look at the Xml of the document I see that you can use expressions on textfields that hold some code. I think I would need to write some code for the group representing the article lines right?
Below is the xml part of the article line:
<detail>
<band height="38" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-19_1" style="column_field_small" x="228" y="2" width="264" height="12" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{articleDescription}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-20_2" style="column_field_small" x="5" y="2" width="222" height="12" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{articleCode}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="staticText-31_5" style="sub_column_header_small" x="229" y="14" width="39" height="12"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Quantity}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="staticText-32_6" style="sub_column_header_small" x="272" y="14" width="24" height="12"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Pack}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="staticText-33_7" style="sub_column_header_small" x="415" y="14" width="52" height="12"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Grossweight}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="staticText-34_8" style="sub_column_header_small" x="469" y="14" width="61" height="12"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Nettweight}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
<reportElement key="textField-21_3" style="sub_column_field_small" x="490" y="26" width="40" height="12"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{finalNetWeight}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
<reportElement key="textField-22_4" style="sub_column_field_small" x="427" y="26" width="40" height="12"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{finalGrossWeight}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-23_5" style="sub_column_field_small" x="272" y="26" width="24" height="12"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{finalPackageCode}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="###0" isBlankWhenNull="true">
<reportElement key="textField-24_6" style="sub_column_field_small" x="228" y="26" width="40" height="12"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{finalQuantity}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-23_5" style="sub_column_field_small" x="300" y="26" width="80" height="12"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[( $F{serialCode} != null && $F{serialCode}.length() > 0 ? $F{serialCode} :
( $F{customersPalletCode} != null && $F{customersPalletCode}.length() > 0 ? $F{customersPalletCode} :
( $F{lotCode} != null && $F{lotCode}.length() > 0 ? $F{lotCode} : "" )) )]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="staticText-32_6" style="sub_column_header_small" x="300" y="14" width="80" height="12">
<printWhenExpression><![CDATA[new Boolean(1==2)]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.SerPltLotCode}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="staticText-32_6" style="sub_column_header_small" x="380" y="26" width="43" height="12"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["(" + ( $F{serialCode} != null && $F{serialCode}.length() > 0 ? $R{CWjp.Serial} :
( $F{customersPalletCode} != null && $F{customersPalletCode}.length() > 0 ? $R{CWjp.Pallet} :
( $F{lotCode} != null && $F{lotCode}.length() > 0 ? $R{CWjp.Lot1} : "" )) )
+ ")"]]></textFieldExpression>
</textField>
</band>
</detail>
This sounds like a job for Groups. Keep in mind that the data must be sorted before grouping should be applied.