Blog

Number Existing Tables

Many tables in ServiceNow have number fields, for example, the Incident table has INC0010213. These numbers are used to quickly identify records.  

Some tables in ServiceNow do not have a number field, but they probably should.  For example the Outage [cmdb_ci_outage] table.

In this example below, you can add a number field to the Outage [cmdb_ci_outage] table:

Step 1: Find the Outage Form.  

The Outage form isn't on the left navigator.  To get the outage form, in the "Type Filter Text", type cmdb_ci_outage.list

Step 2: Add the Number field to the Outage Form.

Right Click > Personalize > Dictionary > New

Table: Outage [cmdb_ci_outage]
Column Label: Number
Column Name: u_number
Type: String
Max Length: 40
Default value:
javascript:getNextObjNumberPadded();

Step 3: Add Number Maintenance

Note: if you skip step 2, adding the number maintenance record will automatically create the u_number field in the cmdb_ci_outage table.

Number Maintenance: 
Table: cmdb_ci_outage
Prefix: OUT
Number: 10,000
Number of digits: 7
Table: Outage [cmdb_ci_outage]

Step 4: Give existing outages, outage numbers

Note: This is manual step and not captured in an update set.  Always run Scripts - Background in a DEV environment first and test.

1. Elevate Privilege to security_admin.
2. In type filter text, type sys.scripts.do

(function() {
    var grOutage = new GlideRecord('cmdb_ci_outage');
    grOutage.addQuery('u_number','');
    grOutage.query();
    while(grOutage.next()){
        grOutage.u_number =new NumberManager(grOutage.sys_meta.name).getNextObjNumberPadded();
        grOutage.setWorkflow(false); //Do not run business rules
        grOutage.autoSysFields(false); //Do not update system fields
        grOutage.update();
    }
})();

Step 5: Optional: Unique Field

To make the new u_number field unique, you can Personalize dictionary and check the unique checkbox.  However you should only check this box once all outage records are unique.