Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Mass search serial numbers that contain text?

StephanieH04070
Kilo Contributor

Hello, I need to search the hardware table for 100s of serial numbers but only part of the serial numbers is given.  Is there a way to mass search serial numbers that contain xyz?  For example, I am given 1309531, 131952 and 1420341 but the database might have 1 or 2 leading zeros so I would have to search each serial number with " * " in front of it.  Or maybe there is a report I can run similar to this type of search?

2 REPLIES 2

Brad Bowman
Mega Patron

Hi Stephanie,

You could enter these in the search criteria one at a time, like this

BradBowman_0-1765993514419.png

or in the filter navigator with an OR between each

BradBowman_1-1765993594057.png

If your search criteria will contain hundreds of values, it would be easiest to find the records via a Fix Script like this:

var snArr = ['1309531', '131952']; //paste in a list from Excel...
var arrayUtil = new ArrayUtil();
var hwArr = [];
var hw = new GlideRecord('alm_hardware');
hw.query();
while (hw.next()) {
	var sn = parseInt(hw.serial_number,10);
	if (arrayUtil.contains(snArr, sn)) { //serial_number of this record found in the list
        hwArr.push(hw.sys_id.toString()); //or use serial_number, asset_tag,...
	}
 }
 gs.print(hwArr.join(','));

Then you can copy the entire value from the script dialog window and paste it into a list view filter to get a list of the actual hardware records

BradBowman_2-1765995322350.png

 

 

 

 

StephanieH04070
Kilo Contributor

That's super helpful!  I'll try that.