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!

@Grant I couldn’t find this anywhere else in the documentation or forum posts, so feel free to move it, but figured this would be an appropriate place to post this bit of info that might be helpful for future users. It’s kind of a convoluted process at present!

How to determine what query a report or label is linked to in Specify 7:

If you cannot remember which query a given report or label is linked to, but want to edit the fields in the query (for example, to add a new field to a report or label), you can find it by doing the following:

Navigate to report/label definition in your collection’s App Resources, then click the pencil icon to the right of the name.


A dialog will pop up, click the button labeled “Labels”

A new dialog will pop up, click the pencil icon to the right of the “Query” field:

One final dialog will pop up, containing the name of the Query linked to the label and its owner!

Alternatively, you can also use this query to check all queries and reports/labels:

Report and Label Ownership Query.json (2.0 KB)

1 Like

Hi @nfshoobs,

Thank you so much for writing this up! :clap: