Naming Series count break in random occasions

I have created a custom DocType named “Short Leave Application”, and it’s naming series is set as below,

Naming Rule: Expression

Auto Name: format:HR-SLA-{YYYY}-{####}

For the first few documents, the naming series worked fine,

But after many entries, it has skipped 408 counts from 235 to 643,

The above records were sorted according to the ID and there were no records created in between.

@ransikerandeni someone with full access to your website changed the counts of your document from 235 to 642 .

No, when I last checked the count from Document Naming Series, it was displayed as 163, but was naming around 2000.

Naming series is a global counter. So if you used .#### for the counter, then any DocType that has a .#### counter in their naming series will update that counter. So if you create 0001 in one DocType, then if you create a record in another DocType with a .#### series, it will create as 0002.

Is there any option to set the counter to start from “0” in newly created custom DocTypes?

You can use Document Naming Rule for this:

Navigate to Home → Document Naming Rule and click New.

  1. Select your Document Type (your custom DocType) from the dropdown.
  2. Set a Priority value (e.g., 10 for higher precedence — higher values are applied first).
  3. In the Naming section, enter your desired Prefix (e.g., "CUST-") and specify the Counter Start value (the number from which naming should begin).
  4. Save the rule.
2 Likes

In ERPNext, using Document Naming Rule, you can start a counter from 0 by creating a custom Naming Series for your DocType. For Eg in Document naming rule set : DOC- and select the doctype. give the prefix and start series from.

Just see the screenshot:

1 Like

If I want to use this format HR-DSR-{YYYY}-{####}. What should I enter in the “Prefix” in Document Naming Rule?

Set Prefix to HR-DSR-.YYYY.- and set digits to 4

Write prefix like HR-DSR-.YYYY.-

For your reference:

  • Allowed special characters are “/” and “-”

- Optionally, set the number of digits in the series using dot (.) followed by hashes (#). For example, “.####” means that the series will have four digits. Default is five digits.

- You can also use variables in the series name by putting them between (.) dots
Supported Variables:

- .YYYY. - Year in 4 digits

- .YY. - Year in 2 digits

- .MM. - Month

- .DD. - Day of month

- .WW. - Week of the year

- .FY. - Fiscal Year

If we want to use a DocType Field value how can we use it in the series?

Example: If there is a Field name "called “custom_main_procurement“, and I want to use that value in the naming series, how to use that in the naming series?

format:RFQ/{custom_main_procurement_type}/.YYYY.

If a naming series is defined in the DocType, it will get override with the “Document Naming Rule”?

Use Like this RFQ/.{custom_main_procurement_type}./.YYYY.-

Yes Document Naming Rule Override naming series as it have highere priority then Naming Series

1 Like

If we are to use a naming series like “RFQ/.{custom_main_procurement_type}./.YYYY.-”, which includes a field name, then it is not possible to use “Document Naming Rule”, right? Instead, we have to use DocType’s naming series? And if we use DocType’s naming series, is there any way to keep the count in order without skipping?

You Can Use Document Naming Rule with fieldname, it works

use the document naming setting tool

Once we set the prefix in the DocType naming series or from the “Document Naming Rule”, the prefix won’t be displayed in the prefix list in the “Document Naming Settings”. If type the prefix manually without selecting, it’ll set the count globally.

Are you having two sites in same server?
or same naming series is used by any other form?

  • The prefix list in Document Naming Settings only displays naming prefixes that are configured or predefined globally.
  • Custom prefixes set within a DocType or naming rule are local to that DocType and hence not synced to the global prefix list.

If you want a specific starting number for the suffix, you can configure the Counter field in the Document Naming Rule.
For example, if you set the counter to 100, the next generated document will begin from 101.

Thank you for the Info. It was useful. I want to know when using a Document Naming Rule, if we use something like this RFQ/.{custom_main_procurement_type}./.YYYY.- is it possible to reset the counter once the Year has passed from 2025 to 2026?

Example RFQ/TEST/2025/0891 to **RFQ/TEST/2026/0001
**
If we have to set a Rule Condition, how to apply it?

As far as I know, the counter automatically resets when the year changes.
So you don’t need to reset the counter manually.