How to populate Serial Numbers of all the CI into Serial Number table in ServiceNow

Priyanka84
Tera Contributor

Hi,

We are trying to get the serial numbers related to all the CIs into serial number table(cmdb_serial_number). Can someone guide us how we can achieve this.

find_real_file.png

Thank you!!

4 REPLIES 4

Not applicable

The easiest way I can think of is to write a script to handle this for you.
You can query cmdb_ci where serial number is not empty, then iterate through and create a new record in cmdb_serial_number.
I would check to see if an existing serial number exists in cmdb_serial_number by querying where cmdb_ci is the ci you are currently iterating on.  If one exists I would either update it, or skip to the next CI and leave the existing cmdb_serial_number record.
The new record in cmdb_serial_number will need a few fields populated:

  • The reference back to the ci in the cmdb_ci field
  • The serial number in the serial_number field
  • False in the absent field
  • True in the valid field
  • And a serial number type in the serial_number_type field (by default this should be 'system')

Optionally, you could null out the serial number on the cmdb_ci record after you create the new cmdb_serial_nuber record.

SumanthDosapati
Mega Sage
Mega Sage

Hi,

You can run a background script to do that.

Navigate to 'Scripts - Backround' from left navigator

var ci = new GlideRecord('cmdb_ci');
ci.addNotNullQuery('serial_number');
ci.setLimit(10);  //add this line to first test for 10 records
ci.query();
while(ci.next())
{
    var sn = new GlideRecord('cmdb_serial_number');
    sn.initialize();
    sn.serial_number = ci.serial_number;
    sn.cmdb_ci = ci.sys_id;
    sn.insert();
//uncomment below two lines if you want to clear the serial number in cmdb_ci table after creating record in cmdb_serial_number table
//ci.serial_number = '';
//ci.update();
}

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

Hi,

Any update?

Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.

Regards,
Sumanth

Note that you would need to add the following fields/value on insert:

  • False in the absent field
  • True in the valid field
  • And a serial number type in the serial_number_type field (by default this should be 'system')

If these values aren't present the IRE lookup on serial number will not work.  This could cause a lot of issues if using any integrations that leverage the IRE.

I would also note that you should check for existing serial numbers as to not create duplicates.