Catalog Number Regular Expression Formatter Set Up

:book: This guide explains how to set up a Regular Expression for a Catalog Number format and provides an example of a Regular Expression for the Accession Number.

Regular Expressions in Field Formats

UI Formatters can be defined that enforce a format according to a regular expression.

The Field Formatters are defined in an app resource at the discipline level. Access the App Resources by clicking on your :usercircle_: Username and selecting :document: App Resources.

Use the panel on the left of the App Resources page to navigate to the appropriate discipline and select # Field Formatters. If you don’t have a Field Formatters resource, click on the :plus_: Add Resource button. In the dialog asking for a Resource Type, click on :gear_: App Resource, and then on # Field Formatters.

Select the table you want to add the new format to and press Add

Next, press Add Field and select Regular Expression as the type. Both the value and pattern attribute should be enforced.

After saving, this makes the regex formatter available. It must then be assigned to the field in the schema configuration using the name that was given to the new formatter.
To set the format in the schema configuration:

  1. Log into Specify as an admin user.

  2. Go to :usercircle_: Username:schema: Schema Config.

  3. Select your language from the Available Locales.

  4. In the list of tables, scroll down and select CollectionObject.

  5. In the list of fields that appears, select catalogNumber.

  6. Expand the drop down list next to the Field Format line to see the different Catalog Number format options.

  7. Select the new format you created in the UI Formatters file.

  8. Press Save

  9. Open the Collection Object form to make sure your new UI Formatter is still being correctly assigned to the Collection Object’s Catalog Number field.

[!note]
If the Catalog Number hasn’t updated, try logging out and logging back in.


Example Implementation

Question

From Ben Richardson at the Western Australia Herbarium:

Is there a way to define a field formatter in Specify v7.9.6.2 that optionally ends with a final letter, e.g. ACC/10001 A, where 10001 is incrementing and the added space and uppercase letter must be unique for the incremented number if it exists?

Answer

In your Field Formatters App Resource for the collection/discipline, you can configure a format like the one you’ve described here:

After this is set, you should see ACC/#####( [A-Za-z])? shown in the preview for the field. Now you can enter ACC/10001 A and it will be valid! It will also increment based on your postfix.

Accession Number Preview

To make this look much nicer and be easier for the user, you can update the Accession view definition so that it uses the appropriate default (add default="ACC/#####" to the field):

<cell type="label" labelfor="1"/>
<cell type="field" id="1" name="accessionNumber" uitype="formattedtext" default="ACC/#####"/>

That’s better! :tada:


Now you can create Accession records with an Accession Number that may or may not have a postfix. It also supports incrementing based on the postfix!

Video Demonstration:

1 Like