You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Server-Side Components/Background Scripts/Duplicate Finder/readme.md
+25-5Lines changed: 25 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,11 @@
1
-
## ServiceNow Duplicate Record Finder
2
-
A simple server-side script for ServiceNow that finds and reports on duplicate values for any field on any table. It uses an efficient GlideAggregate query and formats the results into a clean, readable report.
3
-
1
+
# ServiceNow Duplicate Record Finder
2
+
A simple server-side script for ServiceNow that finds and reports on duplicate values for any field on any table. It uses an efficient `GlideAggregate` query.
3
+
## Find Duplicates by Single Field - `findDuplicatesBySingleField.js`
4
+
This finds duplicates based on a single field which matches
4
5
### How to Use
5
6
This script is designed to be run in **Scripts - Background** or as a Fix Script.
6
7
1. Navigate: Go to **System Definition > Scripts - Background** (or type sys.scripts.do in the filter navigator).
7
-
2. Copy Script: Copy the entire contents of the script.js file.
8
+
2. Copy Script: Copy the entire contents of the `findDuplicatesBySingleField.js` file.
8
9
3. Paste and Configure: Paste the script into the "Run script" text box. Add the table to search in `tableName` and the field to search for duplicates in `fieldName`
9
10
```js
10
11
// Update ONLY below values to find duplicates
@@ -22,6 +23,25 @@ This script is designed to be run in **Scripts - Background** or as a Fix Script
22
23
var fieldName ='short_description';
23
24
```
24
25
25
-
26
26
4. Run Script: Click the "Run script" button. The results will be displayed on the screen below the editor.
27
27
28
+
## Find Duplicates by Field Combination - `findDuplicatesByCombination.js`
29
+
This is a more powerful script that finds duplicate records based on a unique combination of one or more fields.
30
+
31
+
### How to use
32
+
This script is also designed to be run in **Scripts - Background**
33
+
1. Navigate: Go to **System Definition > Scripts - Background**
34
+
2. Copy Script: Copy the entire contents of the `findDuplicatesByCombination.js` file.
35
+
3. Paste and Configure: Paste the script into the "Run script" text box. Update the `tableName` field and the `fieldNames` array. The `fieldNames` variable is an array, so even a single field must be enclosed in square brackets `[]`
36
+
37
+
```js
38
+
// --- UPDATE ONLY THE VALUES BELOW ---
39
+
var tableName ='<table_name>'; // The table you want to check.
40
+
var fieldNames = ['field_1', 'field_2']; // An array of fields for the unique combination.
41
+
```
42
+
43
+
For example, to find models with the same name, model number and manufacturer
44
+
```js
45
+
var tableName ='cmdb_model';
46
+
var fieldNames = ['name', 'model_number', 'manufacturer'];
0 commit comments