- 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
02-14-2024 06:07 AM - edited 02-14-2024 06:18 AM
the comment about using a script include is probably best.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 06:13 AM
Hi @_bhishek
Create a report and group by Serial number.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- 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-06-2024 06:17 AM
When I try the accepted solution (code is copied and pasted), I get a report that lists out all the records with an empty serial number and no other records, but I know there are other records that have actual values that are duplicated. Any ideas on why that is or how to correct it?