Sequences Page

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 DirectoriesDocuments 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. 

Note:  Sequences are only used in application. System instances should be numerated manually.


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.

Note: If the current serial number conatins leading zero, the sequence will use the same format as long as possible. (E.g next value for A-007 is A-008, but next value for A-999 is A-1000).


Unique sequences
If the sequence is marked as unique, the system will make sure that all serial numbers are unique inside each data type. If user defines a serial number manually and it already exists, a DomainModelException is thrown. If a serial number generated by the unique sequence allready exists for some reason, it's prefix is extended with an additional number (E.g. A-76 will be changed to A(1)-76).


Shared sequences
Regular sequences maintain current state for each data type independently. The sequence marked as shared uses common current states for all data types. If the shared sequence is also unique, then uniqueness is checked for all data-types which use this sequence together, not for each separately.


Periodic sequences 
Possible values of a sequence's period are: NONE, YEAR, QUAERER, MONTH, WEEK, DAY and HOUR. If it's not equal to NONE, the sequence is called periodic. Periodic sequences also require a Timezone to be selected. They can only be used for Documents, as only documents have a document timestamp shared field (See System defined shared fields for more details).
When periodic sequence S is asked to generate a new serial number for an instance of type T with timestamp D:
  • 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.

Note: If the periodic sequece is also unique, then uniqueness is checked only inside current period. For example, if the period is YEAR we can have both document #A-47 dated 07.04.2017 and document #A-47 dated 07.04.2018.