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 field formatters can be defined that enforce a format according to a regular expression.

The UI field formatters are defined in an app resource at the discipline level. Access the app resources as an admin user by clicking on your user name and selecting Resources then App Resources.

Use the panel on the left of the App Resources page to navigate to the appropriate discipline and click on the Add Resource button. In the dialog asking for a Resource Type, click on App Resource and then on Field Formatters.

First, select the table you want to add the new format to and press wrap=“greenBtn”]Add[/wrap]

Next, press wrap=“greenBtn”]Add Field[/wrap] and select Regular Expressin as the time. The value attribute should be the regular expression to be enforced. The pattern attribute will be used as the mouse-over hint for the field.

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 Select → Schema Configuration.

  3. Select your language from the Available Locales and click Edit a Schema.

  4. In the list of tables, scroll down to collectionobject and click it to select.

  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. The new format you created in the UI Formatters file should be there. Select it.

  8. Click OK.

  9. Restart Specify.

  10. In the Schema Configuration window, make sure your new UI Formatter is still being correctly assigned to the Collection Object’s Catalog Number field.


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” (UIFormatters) 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