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

Can you check if you have written any business rule (on before) to abort update on that table? (setAbortAction)



Thanks


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


Yes there are few Business rules with Abort action. I disabled all of them and tried the script but still it did not update the record with numbers.



Thanks,


Jag.


Are you able to update number manually on a record?



Thanks


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


Hello Alikutty,



I am able to update the record manually.



Thanks,


Jag.


Try to write an on after business rule on the table and execute the code by forcing an update on record with a value change.



Thanks


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