Sequencers

Sequencers allow you to create complex alphanumeric sequences (a prefix followed by a sequence number) such as invoice numbers or other serial identifiers.

To configure a sequencer:

  1. In FintechOS Studio, go to Main Menu > Advanced > Sequencers.
  2. Click Insert to add a new configuration or open an existing one by double-clicking it.
  3. Fill in the following:
    Fields Description
    Name Insert a name for the sequencer.
    Code Insert a unique code for the sequencer. You will use this code to call the sequencer via server side scripts using the getSequenceNumber function.
    PrefixInsert an alphanumeric prefix for the sequences. For example, if you set the prefix to AAA, the sequences will be AAA1, AAA2, and so on.
    PaddingThis is the number of characters for the sequence number. For example, if you set the padding to 4, the sequence numbers will be 0001, 0002, and so on.
    RangeMinInsert the minimum sequence number.
    RangeMaxInsert the maximum sequence number.
    NumberThis is the current number in the sequence (which will be returned on the next sequencer call). You can use it to set the initial number of the sequence or to manually advance the sequence to a specific number. As the sequencer is used, this field updates automatically to indicate the current sequence number.
    Start dateDate when the sequencer becomes available.
    End date Date when the sequencer will be disabled.

    Filter JS

    JavaScript code that allows you to process or filter the sequence numbers. The following variables are predefined.
    • sequenceNumber - numeric value representing the current sequence number.
    • skip - boolean value instructing the sequencer to skip the current sequence number. Default: false.
    Example: Skip even numbers and return only odd numbers:
    Copy
    skip = (sequenceNumber % 2 == 0);
     
    Example: If the sequence number contains 666, skip it and replace it with 667. This implies, for example, that 666000 becomes 667000, and we actually skip 1000 numbers. This covers the left most match only, as the other matches will be skipped automatically.
    Copy
    var s = sequenceNumber.toString();
    var m = s.match(/666/);
    if(m) {
        var rightPaddingZeroes = s.length - m.index - '667'.length;
        s = s.substring(0, m.index) + '667' + Array(rightPaddingZeroes + 1).join('0');
        sequenceNumber = s;
    }
  4. Click Save and reload.

Roll the Sequencer Back or Forward

You can use the Sequencer Items grid at the bottom of the sequencer page to manually roll the sequencer back or forward. The sequencer will always jump to the first sequence number in the grid that is manually marked as not used and then resume numbering from there, reusing any allocated sequence numbers in the process.

For instance, in the example below, the sequencer is currently at number 30.

If we manually uncheck the Is Used flag for sequence numbers 15 and 20 (as shown above), on the next call, the sequencer will reallocate number 15. Then, it will reallocate numbers 20, 21, 22, 23, etc. all the way to 30. Then, it will resume allocating new numbers: 31, 32, 33, etc.

To add a sequencer item:

  1. In the Sequencer Items grid, click Insert.
  2. Fill in the follosing fields:
    Fields Description
    isUsed
    • Default state (neither checked, nor unchecked) - Doesn't affect the sequencer behavior. Leave it like this if you plan to activate the sequence number later by unchecking it.
    • Unchecked - Activates the sequence number and forces the sequencer to jump to it on the next iteration (provided there are no other lower sequence numbers set up identically).
    • Checked - Doesn't affect the sequencer behavior. Manually unchecked sequence numbers will transition to the checked state once they are allocated by the sequencer.
    SequencerIDThis field is automatically filled with the sequencer code.
    Number Insert the sequence number you want to customize.

    Name

    Insert a name for the customized sequence number.
  3. Click Save and close.

Retrieve a Sequence Number from the Sequencer

You can call the sequencer using Server Automation Scripts via the getSequenceNumber Server SDK function.

HINT  
To optimize concurrent access to the sequencer, avoid locking the sequencer for an extended time. Try to optimize your scripts' code so that the sequencer logic runs only when necessary. Also, try to trigger the sequencer call toward the end of the script, so that the lock remains set for a shorter time.