- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 06:16 AM
Hello experts,
I need to know all users who are managers from my Company.
To obtain it, I have created a report using table [sys_user] with fields:company,department and manager. But the problem is that I obtain duplicated reports (as many as the number of users managed by each manager). How could I remove this records from my report? How could I obtain this report with only one record per manager?
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Reporting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2019 03:09 AM
It depends you can run a background script to remove the duplicates otherwise a less drastic approach would be if 'Duplicate' is mentioned in the closure codes just add a condition that says 'Close code (is not) Duplicate'.
Let me know if this answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 06:29 AM
Hi,
If it's just to get some sort of count, you can just use "group by" and user. This way they all stack in one line for you.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 06:39 AM
From https://www.servicenowelite.com/blog/2013/11/22/duplicate-record-scripts
Script below will give you a report, you'll just have to throw in the deleteRecord() function (https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_ScopedGlideRecordDeleteRecord)
gs.print(getDuplicates('sys_user','user_name'));
function getDuplicates(tablename,val) {
var dupRecords = [];
var gaDupCheck = new GlideAggregate(tablename);
gaDupCheck.addQuery('active','true');
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
05-06-2019 11:09 AM
But I need to obtain a report to be exported to Excel file...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 11:56 AM
Well, worse come to worse, you can always export it to Excel, then use the remove Duplicates feature in Excel (you get to pick the field on which to compare for duplicate).
I know that's the worst case scenario, but would end your issue.
Please mark reply as Helpful/Correct, if applicable. Thanks
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!