Finding Duplicate Assets

AndyB5000
Mega Guru

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;
}

find_real_file.png

 

The above screenshot shows the returned list.  This is from my PDI as I am testing the script..

 

thanks in advance for any assistance.

 

 

 

14 REPLIES 14

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.

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? 

I used the code you put in your post.  I am calling the script include dynamically in the list filter to call the records.

find_real_file.png

 

each time I get all duplicate records and not the unique ones.

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,

Create scripted filters

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;
}