Here’s a script for a sequence with floating zeros:
function get()
{
var q = "SELECT Value From dbo.ProgramSettingValues WHERE Name = 'SequenceNumber'";
var r = sql.Query(q).First;
var sequenceNumber = r;
if (r == null)
{
var q = "INSERT INTO dbo.ProgramSettingValues (Value, Name) VALUES ('1', 'SequenceNumber')";
sql.Exec(q);
sequenceNumber = 1;
}
else
{
sequenceNumber++;
}
q = "UPDATE dbo.ProgramSettingValues SET Value = '"+sequenceNumber+"' WHERE Name = 'SequenceNumber'";
sql.Exec(q);
return Helper.Format(sequenceNumber,'0000');
}
function reset()
{
q = "UPDATE ProgramSettingValues SET Value = '0' WHERE Name = 'SequenceNumber'";
sql.Exec(q);
}
When you need to get a value for a ticket tag use {CALL:orderNumber.get()}
Whatever rule you use for resetting create the following action and add it to the rule:
Action Name: Execute Script
Action Type: Execute Script
Function: [:Function x.y()]
Run in Background: False
In your reset counter rule:
Function x.y(): orderNumber.reset()
This will give you 0001, 0002, etc. which should help with your sorting issue.