RIDING BYTES
← All insights

November 28, 2026 · 6 min read

The SENAITE ID Server: sample IDs that survive audits

How SENAITE builds sample IDs, what the split length really does, how to reset the counter every year, and how to change a running ID scheme without collisions.

The SENAITE ID Server: sample IDs that survive audits

A sample ID ends up on the bottle, on the report, in the client’s emails and in their spreadsheets. It will be quoted back to the lab years after the sample was thrown away. Of everything configured before go-live, the ID scheme is the part that is hardest to change later, because every change leaves two numbering systems in the record.

SENAITE generates IDs with its ID Server. It is configured in the setup on the tab ID Server, in a table with one row per content type.

The table

ColumnWhat it does
Portal TypeThe content type the row applies to
FormatThe ID template, e.g. {sampleType}-{seq:04d}
Seq Typegenerated (a stored counter) or counter (counts objects)
Context, Counter Type, Counter RefOnly for counter; rarely needed
PrefixNot used for numbering; leave the default
Split LengthHow much of the format defines the counter (see below)

Samples have the portal type AnalysisRequest, for historical reasons. Out of the box, samples, worksheets (WS-001), batches (B-001), reference samples (QC-001) and a few other types have a row. Types without a row get a generic ID from their type name.

ID server table in the setup with columns Portal Type, Format, Seq Type, Context, Counter Type, Counter Ref, Prefix and Split Length. Rows include Worksheet WS-{seq:03d}, AnalysisRequest {sampleType}-{seq:04d} and the partition, retest and secondary formats.
The ID server table of a training site. Samples use {sampleType}-{seq:04d}, so drinking water samples become DW-0001, DW-0002 and so on.

The default sample IDs

The default format for samples is {sampleType}-{seq:04d}. With a sample type whose Sample Type Prefix is DW, samples are numbered DW-0001, DW-0002 and so on. The counter is kept per sample type, so the first wastewater sample is WW-0001 regardless of how many drinking water samples came before.

Samples derived from other samples get rows of their own:

A sample that is aPortal typeDefault format
partitionAnalysisRequestPartition{parent_ar_id}-P{partition_count:02d}
retest of an invalidated sampleAnalysisRequestRetest{parent_base_id}-R{retest_count:02d}
secondary sampleAnalysisRequestSecondary{parent_ar_id}-S{secondary_count:02d}

All of them are technically AnalysisRequest objects. The ID Server recognises what kind of sample it is building and picks the matching row, which is how DW-0042-P01 and DW-0042-R01 can look different from each other and from DW-0043. The {parent_base_id} variable strips an existing suffix, so the retest of a retest becomes DW-0042-R02, not DW-0042-R01-R01.

The variables

VariableValue
{seq:04d}The counter, zero-padded to four digits
{alpha:2a3d}Alphanumeric counter: AA001, AA002, …, AB001
{year}Two-digit current year, e.g. 26
{yymmdd}Current date, e.g. 261128
{sampleType}The sample type prefix (samples only)
{clientId}The client ID (samples only)
{dateSampled}, {samplingDate}Sample dates, with strftime codes, e.g. {dateSampled:%Y}

Padding is a minimum, not a limit. After DW-9999 comes DW-10000. An alphanumeric counter needs both a letter and a digit count: {alpha:3a1d} is valid, {alpha:4a} is not.

Split length: the setting everyone gets wrong once

The ID Server does not keep one counter per row. It keeps one counter per key, and the key is built from the beginning of the format. The format is cut into segments at each dash and at each variable, and Split Length says how many of those segments form the key.

For the default {sampleType}-{seq:04d} with split length 1, the key is the sample type prefix. That is why every sample type has its own counter.

Now the common request: “the number should start at 1 every year”. The obvious attempt is:

  • Format {sampleType}-{year}-{seq:04d}, split length 1

The IDs look right (DW-26-0001), but the key is still only {sampleType}. On 1 January the year in the ID changes and the counter keeps going: DW-27-0815. The fix is to include the year in the key:

  • Format {sampleType}-{year}-{seq:04d}, split length 2

Now the key is {sampleType}-{year}, a new key starts every year, and the first sample of 2027 is DW-27-0001. The same logic applies to {yymmdd}: a daily counter needs the date inside the split length, otherwise the date is decoration and the counter runs on.

The reverse case is just as useful. A format like {year}{seq:05d} with split length 1 has the key {year}: one counter for all sample types, reset every year, giving 2600001, 2600002.

Where the counters live

The counters are stored in the database, next to the samples. A restore from backup brings the counters back to the matching state, with no external service to keep in step.

Site managers can see and change them in Manage Number Generator (the view ng of the site). It lists each key with its current value, and from SENAITE 2.7 on also the next ID each key will produce. Two situations need it:

  • Migration from another LIMS. If the old system ended at DW-26-0412, set the counter for that key to 412, and the first SENAITE sample continues at DW-26-0413.
  • Checking a format change. After changing a format, look at the keys and values the view shows before the first sample is created.
Manage Number Generator view with a tab per type. The Sample tab lists three keys, analysisrequest-WW, -SW and -DW, with counters 5, 4 and 40, the next IDs WW-0006, SW-0005 and DW-0041, and the template {sampleType}-{seq:04d}.
One counter per key. The Next ID column shows what the next sample of each type will be called.

Changing a scheme in production

Changing a format affects only IDs created afterwards. Existing samples keep their IDs, which is the point, but it means the record will show both schemes. Three rules keep it safe:

  1. Change the scheme so that old and new IDs cannot overlap. A different prefix or an added year segment is safe. Shortening the split length can make a new key pick up an old counter value and hand out IDs that were already issued. Within the same client, creating the sample then fails; across clients, two samples end up with the same ID.
  2. Test the new row on a copy of the database first. A broken format stops sample creation for everyone.
  3. Switch at a natural boundary, such as the turn of the year, so the scheme change is easy to explain to clients.

Characters that are not allowed in IDs are normalised away, and sample type prefixes may contain neither spaces nor non-ASCII characters. Keep prefixes short and plain.

Variables of your own

When the built-in variables are not enough, for example a department code or a project number held by an add-on, an add-on can register an adapter for IIdServerVariables. Its get_variables method returns additional values, which every format can then use like the built-in ones. For entirely custom logic, an IIdServer adapter can take over ID generation for a content type. Both are code changes, not configuration.

A checklist for go-live

  • Decide whether IDs are counted per sample type, per client, per year, or across everything, and set split length accordingly.
  • Choose the padding for the volume you expect over the next years, not the next weeks.
  • Decide whether clients should recognise partitions and retests by their ID; the default suffixes -P01 and -R01 are usually fine.
  • If you migrate, seed the counters before the first sample is registered.
Two people reviewing notes on paper next to a laptop

Bring this to your lab

Whether you are evaluating SENAITE, scaling it across sites, or wiring up instruments and monitoring, the team that wrote the platform is the team you talk to.