After ending a work period then starting a new one the order numbers are continuing instead of starting from 1

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);
}

2020-06-25_16;22_1593123760_Samba.Presentation

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:
2020-06-25_16;25_1593123901_Samba.Presentation

Action Name: Execute Script
Action Type: Execute Script
Function: [:Function x.y()]
Run in Background: False

In your reset counter rule:

2020-06-25_16;29_1593124146_Samba.Presentation

Function x.y(): orderNumber.reset()

This will give you 0001, 0002, etc. which should help with your sorting issue.

2 Likes