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

Hello Michael,



I did changed it and tried but no luck.



Thanks,


Jag.


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Since we have no access to your instance to check logs, errors, or see what you are doing, you need to double check the code in the script to make sure the table name is correct on lines 1 and 5, make sure the field name is correct on line 6, etc.   If so I don't have any further ideas for you without more information like errors, etc that you are seeing when you execute the script.


Hello Michael,



I checked for the table name ad field name and they are correct. I also don't see any errors while executing the script and every time it just says script is completed. Please let me know if i need to add any logs in the script.



Thanks,


Jag.


I suggest you execute the same code on a service now developer instance and see if it works. Based on log information My previous script was also not updating your records.



Thanks


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


Hello Alikutty,



Mike's script is working fine in Developer instance but it isn't in our instance. Is there anything that I need to check in our instance for troubleshooting. Could you please help me in getting this done.



Thanks,


Jag.