Finding Duplicate Assets

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 08:03 AM
I have a script include that I found in the community to assist in finding duplicate records in a table. In this case I am using it to locate duplicate assets on the alm_asset table. The script works as expected as it returns a list of duplicated records. So if I have 2 assets that are in the table twice the script return all 4 records. I want to add a line that returns one record so I can create a report showing the duplicated assets.
The script is:
function getDupes(alm_asset, asset_tag) {
var q = new GlideAggregate(alm_asset);
//q.addQuery('active', '=', 'true');
q.addAggregate('COUNT', asset_tag);
q.addHaving('COUNT', asset_tag, '>', '1'); (duplicates)
q.query();
var listOfDupes = new Array();
while (q.next()) {
listOfDupes.push(q.getValue(asset_tag));
}
return listOfDupes;
}
The above screenshot shows the returned list. This is from my PDI as I am testing the script..
thanks in advance for any assistance.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 09:13 AM
Yes, it works..however, what I am looking for is to add a line that returns the unique values of the duplicated assets..
The script returns: A, A, B, B, C, C
But I want it to return: A, B, C
This way I can count how many duplicates I have, so if I have 3 records that have duplicates if will show 3 instead of 6.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 09:48 AM
The above script should return you the unique values [I got unique values in my test case]. Can you post a screen shot of your code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 10:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 10:50 AM
Your filter is not working. Please follow the instructions in the below link. Is your script include Client callable ? [if not, check the client callable checkbox]. Also, post a screenshot of your script include where you defined the function,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 01:03 PM
The filter is working as it returns all assets that are duplicated, in this case there are 10 duplicate assets but I want to see the 5 unique assets.
I used the script you noted in an earlier post.
function getDupes(alm_asset, asset_tag) {
var q = new GlideAggregate(alm_asset);
q.addAggregate('COUNT', asset_tag);
q.groupBy(asset_tag);
q.addHaving('COUNT', '>', '1');
q.query();
var listOfDupes = new Array();
while (q.next()) {
listOfDupes.push(q.getValue(asset_tag));
}
return listOfDupes;
}