Sequences are designed to provide automatic generation of serial numbers (See System defined shared fields for more details) for Directories, Documents and Reports.
How to use sequences?
For Directories, Documents and Reports property "Sequence" is available on type's details page. When this field is set, each time user creates an instance with no manually defined serial number, system asks selected sequence to generate a new serial number.
How does sequence generate serial numbers?
Sequences represent a serial number as a concatenation of some fixed string prefix and a numeric value, which is generated each time the sequence being asked to generate a new serial number (e.g. PREF-0001, VAT1712).
When a data type (T) with selected sequence (S) requests a new serial number for it's instance, system acts like this:
- Find last serial number generated by this sequence for this data type. If this sequence have never been applied for this data type before, the initial value defined for this sequence is used. We will refer to this serial number as "a current state of the sequence S for data type T".
- Split this serial number into string-prefix and numeric value.
- Increment numeric value by 1.
- Update the current state of the sequence S for data type T with a concatenation of old string-prefix and new numeric value.
- Return the current state of the sequence S for data type T.
If user manually set a serial number for an instance of type T which uses a sequence S, manually defined serial number is considered to be a new state of S for type T if and only if its prefix differs from a prefix of current state, or its numeric value is greater then numeric value of current state.
- Find the state of S for data type T.
- Let A be a timestamp of the moment when this state was generated. If A and D are inside different periods (e.g. monthes, years, hours, etc.) the initial state is used as the current state of the sequence S for data type T.
- Perform regular serial number generation, which is described above.