function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chloe BrownChloe Brown 

How to set a max of 4 digits for an Auto Number Field so that it starts at 0 should it get tp 9999?

I am trying to assign max value to an auto number field in order to generate a student number that can only be a certain amount of digits. The auto number may only increment until 9999 - meaning it cannot exceed 4 digits. So once it reaches 9999, it must reset and start at 0 again. Is this possible? Any help would be so appreciated! Thank you.
mritzimritzi
You cant limit the standard auto number field, the way you want.
If you are an admin and want it to be done quickly, create a formula field that will take substring of standard autonumber, and perform mod operation with 9999. Doing this will give you desired result.

Assuming you've a pattern -> AB-0001, Formula
MOD(
  VALUE( RIGHT(Name, LEN(Name)-3) ),
  9999
)

If you are developer, you can use same logic using code without requiring auto number. If there are no records assign 0, if previous records exists, get last created record, get its number increment it by 1 and if its more than 9999 mod it to zero, and save the new record

Work of caution : Assigning same number to multiple students may create inconsistencies in Database as your organisation saves more & more data.
mritzimritzi
If the answer posted above has solved your issue, please mark it as best answer, or add details of any problems you faced after implementing suggestions