- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 05:28 AM
Hi All,
I am able to find the duplicate serial number through background script. I want to create a report with list view in service now for the duplicate serial number assets(alm_asset table).
Could you please help me how can i do that .I am using below script.
var gaDupCheck = new GlideAggregate('alm_asset'); gaDupCheck.addAggregate('COUNT', 'serial_number'); gaDupCheck.addNotNullQuery('serial_number'); gaDupCheck.groupBy('serial_number'); gaDupCheck.addHaving('COUNT', '>', 1); gaDupCheck.query(); while (gaDupCheck.next()) { var gr = new GlideRecord('alm_asset'); gr.addQuery('serial_number',gaDupCheck.serial_number); gr.query(); gs.info('Duplicate serial number: ' + gaDupCheck.serial_number); }
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 06:13 AM
Hello @_bhishek ,
You can create a script include for the same and you can use that script include and use the same in your report.
Create a script include:
var Duplicate_Records_serial = Class.create();
Duplicate_Records_serial.prototype = Object.extendsObject(AbstractAjaxProcessor, {
duplicateRecord: function(){
var numbers = [];
var gaDupCheck = new GlideAggregate('alm_asset');
gaDupCheck.addAggregate('COUNT', 'serial_number');
gaDupCheck.addNotNullQuery('serial_number');
gaDupCheck.groupBy('serial_number');
gaDupCheck.addHaving('COUNT', '>', 1);
gaDupCheck.query();
while (gaDupCheck.next()) {
numbers.push(gaDupCheck.serial_number.toString());
// var gr = new GlideRecord('alm_asset');
// gr.addQuery('serial_number',gaDupCheck.serial_number);
// gr.query();
// gs.info('Duplicate serial number: ' + gaDupCheck.serial_number);
}
//gs.info("Serial_records "+numbers)
return numbers;
},
type: 'Duplicate_Records_serial'
});
and create a report in that call the above script include like this.
Condition: serial number is "javascript:new Duplicate_Records_serial().duplicateRecord()"
Please mark this Accepted and helpful if this worked for you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 08:09 AM - edited 06-20-2024 08:11 AM
I ran into the same issue and it was the condition on the report that was incorrect for me. Try making sure that the condition is:
javascript:new Duplicate_Records_serial().duplicateRecord()
Also, row 9 on the script include should filter out null serial numbers, so it may not be working correctly for you.
A way to test if the script is working correctly is to create two assets with the same serial number and check if they show up in the report.
Edit: The report condition breaks when posting as text but it is:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 12:05 PM
Thank you so much Dylan. Your suggestions proved most helpful. I had to hand type the javascript as I was doing a copy and paste before and though it looked right, I guess it wasn't. I've been able to pull the duplicate records for both asset tag and serial numbers using separate script includes and reports. Yay! Happy Dance! 😀
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 06:51 AM
Stumbled upon this thread and I too am getting the blanked records instead of the non-blanked ones. Followed the instructions provided and ensured I typed out the condition in the field instead of copy and paste. Have applied this both to my DEV and PDI instances that have 100% duplicate serial numbers on a few assets.
However I'm still only able to pull the blanked serial number records. Looking to see @lwhite how you were able to get it to work or if there was something you altered in the script include for yourself.
Much appreciate any assistance.