The number maintenance module allows you to manage all of the numbering for the various tables within ServiceNow. Record numbering really isn’t that difficult to deal with and its very simple to understand as long as you get it set up before the table has records in it. If you have a table with a bunch of data already and you want to assign numbers or IDs to the records in that table, then you need to run a script to assign numbers to all of the existing records along with the typical number maintenance setup. This article explains how to set this up. Thanks to Matt Gaide and Paul Murphy for the script and article idea!

1 Create a new field to store the number or ID

2 Create a new ‘Number Maintenance’ record

3 Run the Script

Navigate to ‘System Definition -> Scripts – Background’ and paste and run the following script.

Note that this script assumes that you are adding numbers to a field called ‘u_number’ on the ‘sys_user_group’ table. As your table and field names will most likely differ from these, you’ll need to replace the instances of ‘sys_user_group’ and ‘u_number’ with the names of the table and field in your situation.

var rec = new GlideRecord('sys_user_group');
rec.addQuery('u_number','');
rec.query();
while(rec.next()){
   rec.u_number =  new NumberManager(rec.sys_meta.name).getNextObjNumberPadded();
   rec.setWorkflow(false); //Do not run business rules
   rec.autoSysFields(false); //Do not update system fields
   rec.update();
}