Create a number sequence
Updated
A number sequence fills the human ID of a dictionary
or the Number of a document. The primary key remains
MetaId — Identity.
Note
Do not declare
ID. The server creates the field. Point the object at the sequence withnumberSequenceMetaId. The server will create a sequence forIDif you omit one. Declaring your own is the usual path.
How to#
1. The file — NumberSequences/<Name>Seq.json in your model, kind
NumberSequence. A new GUID in metaId. Set prefix, padLength,
startValue, increment, resetPolicy.
- Dictionary — start 1000, step 1, no padding, no prefix:
1000,1001. - Document — a short type code and the year in
prefix, six digits, start 1:"prefix": "SO-{YYYY}-","padLength": 6,"startValue": 1givesSO-2026-000001. The product documents follow this pattern (SOsales order,INVrealization,CPcustomer payment,POpurchase order…).{YYYY},{YY},{MM},{DD}resolve on the day the number is taken, not on the document date. resetPolicystaysNone: the counter runs across years, only the year in the prefix changes (SO-2027-000154).
A document whose number goes to a tax authority as an integer reads the
counter, not the whole ID: the Ukrainian tax invoice sends 123 for
INV-2026-000123.
2. Bind it — numberSequenceMetaId on the dictionary or document. On a
dictionary the caption of that field is Code; on a document it is Number.
document.Number in scripts is a shadow of the same value.
3. Bump modelVersion in the same change.
Warning
The counter is committed separately from a test's ambient transaction. Rolling the case back would otherwise reuse numbers a data package has already handed out. If the sequence landed in an occupied range, an insert pulls the pointer up to
MAX(ID)+1once; on PostgreSQL the conflict is caught in a savepoint. Do not assert a specific nextIDafter a rolled-back test — Write an integration test.
What's not there yet#
Reset policies Yearly and Monthly exist on the json (resetPolicy). Up to
the platform build that quotes the reset statement for PostgreSQL, a sequence
with a reset policy fails every insert there with relation "metanumbersequences" does not exist — keep None.