How to Find Duplicates in ServiceNow Tables

Finding duplicate records in ServiceNow can be a pain, especially when you'd like to do it from a list view like so many others before you.

An alternative method we can use to achieve this is by first using scripting to generate a list of values that have 1 or more duplicates.

In doing so, we can subsequently use this list of duplicate values to then filter by in our list view.

  1. Go to Scripts Background in the Filter Navigator.
  2. Run the following or slightly modified script, replacing "YOUR_TABLE" with the table name you are searching, for and "YOUR_FIELD_NAME" with the field value you wish to search for duplicates.
var gr = new GlideAggregate('YOUR_TABLE');
gr.addAggregate('COUNT','YOUR_FIELD_NAME');
gr.groupBy('YOUR_FIELD_NAME');
gr.addHaving('COUNT','>',1);
gr.query();
var duplicates = [];
while(gr.next()){
	duplicates.push(gr.getValue('YOUR_FIELD_NAME'));
}
gs.info(duplicates.toString());

3. Once you have run the above script you should get back a comma-separated list which you can then copy and paste into your list view.

4. In your list view, open the filter options/filter builder. Select "YOUR_FIELD_NAME", then select the filter "IS ONE OF" and paste your comma-separated list into the box provided.

5. After running your search you should see all the required results appearing that are values that are duplicated.

Hope this helps.

Aidan