How to maintain Auto Increment numbering Series?


I am finding it hard to explain my typical requirements.

But let me try and explain.

In Brief
In a custom app that I am creating. I have created a DocType in which I want to have different numbering series based on a field names work_station and current date. So depending on work_station and date the number will increment.

In Detail
I want to maintain one single DocType. In this DocType I want to maintain auto numbering series which will depend on the field work_station and current date.

We have got 20 different Work Stations.

The format of the series is: PRB-{work_station}-DDMMYYYY-####.
Example: PRB-RH01-26082022-0001.

Here if the Work Station and/or date changes the series numbering should start from 1.

For example if a new entry is created for a Work Station then its number would be PRB-RH01-26082022-0002, PRB-RH01-26082022-0003, PRB-TB01-26082022-0001, PRB-TB02-26082022-0001, etc.

And if date changes then the number would be PRB-RH01-27082022-0001, PRB-RH01-27082022-0002, PRB-RH01-27082022-0003, PRB-TB01-27082022-0001, etc.

After experimenting I have understood that it will not to possible to have such varied numbering series. So the best way that I can see is to build some logic to create such series.

Can someone guide in coding such series?


Yogi Yang

I think you would probably need another doctype, where you store the workstation name and it’s according series number (e.g call it workstation_numbers).

when you create a new instance of your doctype, check the entries in workstation_numbers - either retrieve latest number and ++, or create a new one based on the workstation name.


Basically currently this is how naming works…

Naming series has several parts:

  1. Static - just piece of text like “SALES-”
  2. Variables like DD which are replaced with current date/time.
  3. Document fields like customer
  4. ##### which is numerical part of series.

Current implementation of numbering is based on prefix, anything appearing before #### will be static and considered as prefix for counter, anything after that doesn’t matter for counting.

Prefix = anything that appears before first numbering part - #####

So if you use PRB-{work_station}-.####.-.DD.MM.YYYY. then it will work but the inconvenience here is that the date part will be at the end instead of the middle.