Auto Numbering for Existing Records

Jag5
Tera Guru

Hello Experts,

I have created auto numbering for existing software model table. The issue is we have few old records for which we need numbering as well but it works only for newly created records. Is there a way to generate numbering for existing records as well. Thank you in advance.

Thanks & Regards,

Jag.

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Sorry change line 6 to gr.u_number so...


var gr = new GlideRecord("cmdb_software_product_model");


gr.orderBy('sys_created_on');


gr.query();


while (gr.next()) {


  var nm = new NumberManager('cmdb_software_product_model');


  gr.u_number = nm.getNextObjNumberPadded();


  gr.autoSysFields(false);   // Do not update sys_updated_on, sys_updated_by, and sys_mod_count


  gr.setWorkflow(false);       // Do not run any other business rules


  gr.update();


}


View solution in original post

42 REPLIES 42

What is your column name for number field? and also your table name?



Can you please give a screen print of your form with a valid number or its dictionary



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Hello Alikutty,



Please find the screenshot below.



var gr = new GlideRecord('cmdb_software_product_model');  


gr.query();


var prefix   = "SW";    


var counter = "0000000";  


while(gr.next()){


counter += 1;


gr.u_number = prefix+counter;  


}



find_real_file.png



Thanks,


Jag.


Oh, I missed the update(), Please try now



var gr = new GlideRecord('cmdb_software_product_model');


gr.query();


var prefix   = "SW";  


var counter = "0000000";


while(gr.next()){


counter += 1;


gr.u_number = prefix+counter;


gr.update();


}



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Hello Alikutty,



No luck. The number is still showing empty.



Thanks,


Jag.


I think it is because of number conversion from string and backforth, How many records do you have in total can you give me a count of it?



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response