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:
- In FintechOS Studio, go to Main Menu > Advanced > Sequencers.
- Click Insert to add a new configuration or open an existing one by double-clicking it.
- 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. Prefix Insert an alphanumeric prefix for the sequences. For example, if you set the prefix to AAA, the sequences will be AAA1, AAA2, and so on. Padding This 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. RangeMin Insert the minimum sequence number. RangeMax Insert the maximum sequence number. Number This 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 date Date 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.
Copyskip = (sequenceNumber % 2 == 0);
Copyvar 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;
} - 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:
- In the Sequencer Items grid, click Insert.
- 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.
SequencerID This 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. - 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.
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.