The CreatorCon Call for Content is officially open! Get started here.

Turning on Auto-number on existing (custom) table

xiaix
Tera Guru

When I choose find_real_file.png on an existing custom table, I notice that all existing records have (empty) in their new u_number field.   Any new records created, however, will have a number.

Question:   How can I safely populate the u_number field on those existing records?

1 ACCEPTED SOLUTION

Karthik Reddy T
Kilo Sage

Hello David,



Refer the below threads may helpful to you.



Auto Numbering for Existing Records


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

View solution in original post

3 REPLIES 3

Karthik Reddy T
Kilo Sage

Hello David,



Refer the below threads may helpful to you.



Auto Numbering for Existing Records


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

snehabinani26
Tera Guru

HI David,



You need to run a background script to update the existing record as already created record wont get updated from auto_number checkbox.



  1. var gr = new GlideRecord("cmdb_software_product_model");    
  2. gr.orderBy('sys_created_on');    
  3. gr.query();    
  4. while (gr.next()) {    
  5.   var nm = new NumberManager('cmdb_software_product_model');    
  6.   gr.u_number = nm.getNextObjNumberPadded();    
  7.   gr.autoSysFields(false);   // Do not update sys_updated_on, sys_updated_by, and sys_mod_count  
  8.   gr.setWorkflow(false);       // Do not run any other business rules  
  9.   gr.update();    
  10. }  

xiaix
Tera Guru

Thank you both!   I wish I could give a *Correct Answer to each!