- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2018 02:56 PM
I want to check if there are duplicate entries for 'asset tag' on asset table? there are more than 3000 records? is there a way to check that?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2018 03:21 PM
You can create a bar or pie report and group by asset tag. You could also run this script from the 'Scripts -> Background' module.
var table = 'alm_asset';
var field = 'asset_tag';
var gaDupCheck = new GlideAggregate(table);
gaDupCheck.addAggregate('COUNT', field);
gaDupCheck.addNotNullQuery(field);
gaDupCheck.groupBy(field);
gaDupCheck.addHaving('COUNT', '>', 1);
gaDupCheck.query();
while (gaDupCheck.next()) {
gs.print(gaDupCheck.getValue(field) + ': ' + gaDupCheck.getAggregate('COUNT', field));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2018 03:02 PM
Run this in your background Script. It will give you all the Tag names which have duplicate entries. It doesn't check for Duplicate records.
gs.print(getDuplicates('alm_asset','asset_tag'));
function getDuplicates(tablename,val)
{
var dupRecords = [];
var gaDupCheck = new GlideAggregate(tablename);
gaDupCheck.addAggregate('COUNT',val);
gaDupCheck.addNotNullQuery(val);
gaDupCheck.groupBy(val);
gaDupCheck.addHaving('COUNT', '>', 1);
gaDupCheck.query();
while (gaDupCheck.next())
{
dupRecords.push(gaDupCheck[val].toString());
}
return dupRecords;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2018 03:21 PM
You can create a bar or pie report and group by asset tag. You could also run this script from the 'Scripts -> Background' module.
var table = 'alm_asset';
var field = 'asset_tag';
var gaDupCheck = new GlideAggregate(table);
gaDupCheck.addAggregate('COUNT', field);
gaDupCheck.addNotNullQuery(field);
gaDupCheck.groupBy(field);
gaDupCheck.addHaving('COUNT', '>', 1);
gaDupCheck.query();
while (gaDupCheck.next()) {
gs.print(gaDupCheck.getValue(field) + ': ' + gaDupCheck.getAggregate('COUNT', field));
}