Kristen Ankeny
Kilo Sage

NOTE: MY POSTINGS REFLECT MY OWN VIEWS AND DO NOT NECESSARILY REPRESENT THE VIEWS OF MY EMPLOYER, ACCENTURE.

 

This is a quick item that came up recently that I thought would be useful to others. When you define a new table in ServiceNow, you have the option to have it auto-number the records.

 

Screenshot 2023-02-27 at 10.45.08 AM.png

 

By choosing to auto-number, you can define a prefix, a starting number, and a number length. 

 

Screenshot 2023-02-27 at 10.49.18 AM.png

 

 

If you are extending an existing table, for example Incident, you have two options. You can define a custom numbering scheme for your custom table or you can inherit the numbering from the parent. In the case of the former, you would check off Auto-number and define the remaining attributes. In the case of the latter, you would leave Auto-number unchecked and the table would inherit from the Incident table definition (or the numbering definition of the table you extended). 

 

When auto-numbering is turned on, there are two tables used to control the numbering behavior. 

 

  • Number (sys_number): This table captures the table, prefix, starting number, and number of digits. Table records (sys_db_object) reference this record in number_ref. Screenshot 2023-02-27 at 10.57.50 AM.png

 

 
  • Number Counter (sys_number_counter): This table captures the current number the table is at. The record is incremented each time a record using that number is created.

Screenshot 2023-02-27 at 11.02.29 AM.png

 

If auto-numbering is not turned on for your table, records will not be created for your table. So, if you looked at the table number_ref field, you would not see a value. 

 

When you are defining custom tables, it is important to consider if the table will inherit numbering from a table it extends. If it will, do you need this custom table to have unique numbering or can it inherit from the table it extends? If it will not, do you want auto-numbering on this table; will that be useful to users of the system?

 

If, by chance, you end up in a situation where you have a table that auto-numbering was turned on for and you now want to turn that off (either because it doesn't need it or because you want it to inherit numbering from the parent), the solution is simple. I did do some research into this and did find this knowledge article from ServiceNow. However, if I only removed the Number Counter record, it was just getting recreated when a new record was created. I tried a number of other solutions to no avail.

 

In the end, it was the simplest solution that worked. Delete both the Number and Number Counter record for your custom table and the numbering will either stop or start inheriting from the table it extends. 

 

If you find this article helps you, don't forget to log in, bookmark it and mark the article as "Helpful"!

Don't Forget the ServiceNow User Groups!  Sign up and attend one near you!

Comments
sabell2012
Mega Sage
Mega Sage

Thank you for filling in this missing piece of documentation! Very interesting.

p_tishberg
Tera Guru

Great article.  I liked the helpful decision presented: "Delete both the Number and Number Counter record for your custom table and the numbering will either stop or start inheriting from the table it extends"; especially for the custom table inheritance to work correctly - great advice.

GURU3345
Tera Explorer

When form is new and reload the form then number move to next. i want the form is new with same number.

Danny Mortensen
Tera Contributor

@GURU3345 
This might be helpful for your requirement.
Prevent numbering gaps (servicenow.com)

surajkumar95
Tera Explorer

If there is no record created in the table, then how we can get the current number or next number, if we want it in the script include?

Version history
Last update:
‎02-27-2023 08:19 AM
Updated by:
Contributors