Adding a AutoNumber to a table after the fact

Steve42
Tera Expert

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.

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

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,

NUMBER EXISTING TABLES

Numbering Existing Records

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

8 REPLIES 8

AbhishekGardade
Giga Sage

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,

NUMBER EXISTING TABLES

Numbering Existing Records

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade

Thank you,
Abhishek Gardade

Dhananjay Pawar
Kilo Sage

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

Check attached screenshot for more details,

find_real_file.png

 

mark correct/helpful based on impact.

thanks,

Dhananjay.

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.