Adding New Fields to a Report or Label in Specify 7

Currently, you must manually add fields if you update the query associated with a report or label to the JRXML file associated with your report.

This can be accessed by clicking on the :pencil2: icon to the right of the report name after clicking the Reports navigation item at the top of your screen.

Your report’s XML should start with a section like this one (Lines 1-41 in my example):

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.20.0-2bc7ab61c56f459e8176eb05c7705e145cd400ad  -->
<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="Teaching Label" pageWidth="500" pageHeight="230" orientation="Landscape" whenNoDataType="NoPages" columnWidth="440" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" uuid="995e887b-f21b-4671-8e8d-e89241d2f4cc">
	<import value="net.sf.jasperreports.engine.*"/>
	<import value="java.util.*"/>
	<import value="net.sf.jasperreports.engine.data.*"/>
	<field name="1.collectionobject.catalogNumber" class="java.lang.String"/>
	<field name="1,9-determinations.determination.determinations" class="java.lang.String"/>
	<field name="1,63-preparations.preparation.preparations" class="java.lang.String"/>
	<field name="1,9-determinations,4.taxon.Family" class="java.lang.String"/>
	<field name="1,93.collectionobjectattribute.text13" class="java.lang.String"/>
	<field name="1,93.collectionobjectattribute.text14" class="java.lang.String"/>
	<field name="1,63-preparations.preparation.remarks" class="java.lang.String"/>
	<field name="id" class="java.lang.Integer"/>
	<field name="resultsetsize" class="java.lang.String"/>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band splitType="Stretch"/>
	</title>
	<pageHeader>
		<band splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band splitType="Stretch"/>
	</columnHeader>
	<detail>
		<band height="189" splitType="Stretch">
			<textField>
				<reportElement x="102" y="70" width="338" height="22" uuid="8aa17b11-fc12-41a2-875c-1454d93fa67a">
					<property name="com.jaspersoft.studio.unit.width" value="px"/>
				</reportElement>
				<textElement textAlignment="Left" verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{1,9-determinations.determination.determinations}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="0" y="70" width="98" height="22" uuid="ad3b576b-02f3-45af-a9db-ee42a8de66a7"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font isBold="true"/>
				</textElement>

Each piece of your query will display as a <field> component.

<field name="1,63-preparations.preparation.remarks" class="java.lang.String"/>

Query in Specify:

Lines 24-36 in Teaching Label.jrxml:

<field name="1.collectionobject.catalogNumber" class="java.lang.String"/>
<field name="1,9-determinations.determination.determinations" class="java.lang.String"/>
<field name="1,63-preparations.preparation.preparations" class="java.lang.String"/>
<field name="1,9-determinations,4.taxon.Family" class="java.lang.String"/>
<field name="1,93.collectionobjectattribute.text13" class="java.lang.String"/>
<field name="1,93.collectionobjectattribute.text14" class="java.lang.String"/>
<field name="1,63-preparations.preparation.remarks" class="java.lang.String"/>

You can see that Jaspersoft® Studio uses the field name from the file Specify output rather than the user-friendly name assigned to the field in the Schema Config tool. The order of the query is preserved in the JRXML file, making it easy to find the correct field based on its position in the query.

If you would like to add new fields to the report or label, you will need to update the existing query with the new fields.

In this case, I want to add catalogedDate as a field to the report or label.

On my original query, I have added the following field:

Now I need to save the query and once again Define label based on query from the :pencil2: dialog to the right of the query.

You can give this new “label” or “report” any name as we will be deleting it after this step.

Copy the entire section containing the<field> components:

        <field name="1.collectionobject.catalogNumber" class="java.lang.String"/>
        
        <field name="1,9-determinations.determination.determinations" class="java.lang.String"/>
        
        <field name="1,63-preparations.preparation.preparations" class="java.lang.String"/>
        
        <field name="1,9-determinations,4.taxon.Family" class="java.lang.String"/>
        
        <field name="1,93.collectionobjectattribute.text13" class="java.lang.String"/>
        
        <field name="1,93.collectionobjectattribute.text14" class="java.lang.String"/>
        
        <field name="1,63-preparations.preparation.remarks" class="java.lang.String"/>
        
        <field name="1.collectionobject.catalogedDate" class="java.lang.String"/>
        
	<field name="id" class="java.lang.Integer"/>
	<field name="resultsetsize" class="java.lang.String"/>

Once you have this copied, you can Delete the newly generated report or label.

Now navigate to the original label or report in your App Resource viewer.

Select the entire <field> component section and replace it with your newly generated <field> component section.

Important: If you have expressions referencing fields that no longer are available in the field list, they must be removed otherwise the report or label will give an error.

Now you have updated your existing report or label to include your new fields!