- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 09:00 AM
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.
Solved! Go to Solution.
- Labels:
-
Enterprise Asset Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 11:49 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 11:39 AM
Please see my other suggestion below about using the NumberManager API. I believe you will have better success with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 11:29 AM
I would recommend using the NumberManager API. Set your counter via number maintenance to start with whatever number you want and then run the following script in the background. This will update all existing records and then any new records will start with the next number.
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.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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 11:41 AM
Hello Michael,
I tried with the script you gave but it did not update the records.
Thanks,
Jag.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 11:43 AM
I believe Mike has the right approach, Somehow it seems you records are not getting updated.
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 11:49 AM
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();
}