- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:09 AM
I have been asked to create an auto-number system on a table that was not created with one. What I mean is say link on Incident table it starts with INC000001. Is it possible to add a number like this after the table has been created and number what is already there. Not important the numbers for the previous entries but going forward should be in order.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:13 AM
Hello Steve,
Yes we can have numbers for existing records or table created already who do not have number.
You need to generate the number for old records in sequence using a background script and then update the latest counter in your number table for new records.
var gr = new GlideRecord("cmdb_software_product_model"); // your table name
gr.orderBy('sys_created_on');
gr.query();
while (gr.next()) {
var nm = new NumberManager('cmdb_software_product_model'); // your table name
gr.u_number = nm.getNextObjNumberPadded(); // field you want to set the number
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();
}
Check out this blogs,
Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:13 AM
Hello Steve,
Yes we can have numbers for existing records or table created already who do not have number.
You need to generate the number for old records in sequence using a background script and then update the latest counter in your number table for new records.
var gr = new GlideRecord("cmdb_software_product_model"); // your table name
gr.orderBy('sys_created_on');
gr.query();
while (gr.next()) {
var nm = new NumberManager('cmdb_software_product_model'); // your table name
gr.u_number = nm.getNextObjNumberPadded(); // field you want to set the number
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();
}
Check out this blogs,
Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:14 AM
Hi,
You can add this for your table.
Go to table and check auto numbering is on or not.
If not then navigate to number maintenance then create new entry there for your table then after words no will be auto generated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 06:44 AM
Hi Steve,
If this has resolved could you mark this as correct so others will refer same in future for same query also this will remove from unanswered thread.
Thanks,
Dhananjay.