Customizing Table Formats and Aggregations

:warning: This tutorial is for advanced users. We are building a new user interface for creating aggregators, formats, and much more that will be released in the coming months!

Table aggregation establishes how data from a table will appear if more than one record will be returned. For example, a collection object may have more than one determination or collector. Aggregating the determination or collector tables would establish how those would appear in an export or query return.


First, navigate to the User Tools menu, then go to App Resources

From here, you want to make sure you can see App Resources (by clicking the big App Resources button at the top of the page), then navigate to the DataObjFormatters file that applies to your current discipline or collection. In this case, I am editing the file under the Ichthyology collection.

:bulb: Note: If you do not already have a DataObjFormatters file, you can download a copy of the default and load this file into a new Record Formatters app resource at the discipline level.

In the first section, between <formatters> and </formatters>, you have all of the field formats that you can apply to a table/field in queries and on forms.

For instance, here is the format definition for Determiner:

    <format
        name="Determiner"
        title="Determiner"
        class="edu.ku.brc.specify.datamodel.Determiner"
        default="true"
        >
        <switch single="true">
            <fields>
                <field formatter="Agent">agent</field>
            </fields>
        </switch>
    </format>

For a more advanced format, see the default one for Address:

    <format
        name="Address"
        title="Address"
        class="edu.ku.brc.specify.datamodel.Address"
        default="true"
        >
        <switch single="true">
            <fields>
                <field>address</field>
                <field sep=" ">address2</field>
                <field sep=", ">city</field>
                <field sep=", ">state</field>
                <field sep=" ">postalCode</field>
            </fields>
        </switch>
    </format>

See that address, address2, city, state, and postalCode are fields in the Address table. You can use any fields that exist in that table and can define any separator you would like between these fields.


In the second section, between <aggregators> and </aggregators>, you have all of the aggregators that you can apply to a table/field in queries and on forms.

For instance, here is the aggregator definition for Determiner:

    <aggregator name="Determiner"
                title="Determiner"
                class="edu.ku.brc.specify.datamodel.Determiner"
                default="true"
                separator="; "
                ending=""
                count=""
                format="Determiner"
                orderfieldname="orderNumber"
               />

You can add these for any table in the data model, and you can obtain the “class” (i.e. edu.ku.brc.specify.datamodel.Determiner) from the default form definition for each table:

For instance, here is the top section of the Geo Coord Detail <viewdef> component in the form definition for my database:

        <viewdef
                type="form"
                name="GeoCoordDetail"
                class="edu.ku.brc.specify.datamodel.GeoCoordDetail"
                gettable="edu.ku.brc.af.ui.forms.DataGetterForObj"
                settable="edu.ku.brc.af.ui.forms.DataSetterForObj">
            <desc><![CDATA[Sub Collecting Event]]></desc>

            <columnDef>100px,2px,195px,5px,115px,2px,131px,5px,140px,2px,130px,p:g</columnDef>
            <columnDef os="lnx">115px,2px,200px,5px,138px,2px,140px,5px,168px,2px,140px,p:g</columnDef>
            <columnDef os="mac">130px,2px,220px,5px,158px,2px,160px,5px,188px,2px,160px,p:g</columnDef>
            <columnDef os="exp">p,2px,p:g,5px:g,p,2px,p:g(2),5px:g,p,2px,p:g(2)</columnDef>
            <rowDef auto="true" cell="p" sep="2px"/>

I can take the class name from this and define an aggregator or a format to use in the schema config menu. You can see the comprehensive list of all class names here.


We will be releasing a new user interface for this in the coming months! Keep an eye out for more information very soon. If you are a member, please let us know if you need help customizing your formatters or aggregators in a reply to this topic!

I am trying to perform small manipulations within the formatter, like taking only the first letter of the firstName field. I wrote something like this:
<field sep=", ">substring(firstName, 1, 1) + "."</field>
but I get an error that the field name “substring…” is not recognized. The script does not interpret the function name correctly.
What is the correct syntax for such a manipulation, and where can I find documentation on the subject?

Thanks,
Eyal

Answered in Syntax error in custom table format - #2 by Specify