Skip to content

Commit 0141318

Browse files
authored
Update script.js
This script identifies duplicate tickets or tasks in ServiceNow where the number field is not unique. Normally, ServiceNow enforces unique ticket numbers, but misconfiguration at the dictionary level can lead to duplicates. The solution uses GlideAggregate to: -Group records by number and count occurrences. -Filter duplicates where the same number appears more than once.
1 parent 76ba1c9 commit 0141318

File tree

1 file changed

+14
-7
lines changed
  • Server-Side Components/Background Scripts/Get Duplicate

1 file changed

+14
-7
lines changed
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
var dpchk = new GlideAggregate('task');
2-
dpchk.groupBy('number');
3-
dpchk.addHaving('COUNT', '>', 1);
4-
dpchk.query();
5-
while(dpchk.next())
6-
{
7-
gs.print(dpchk.number);
1+
// Table to check (e.g., task, incident, change_request)
2+
var tableName = "task";
3+
4+
var ga = new GlideAggregate(tableName);
5+
ga.addAggregate("COUNT", "number"); // Count how many times each number appears
6+
ga.groupBy("number"); // Group records by number
7+
ga.addHaving("COUNT", ">", 1); // Only show duplicates
8+
ga.query();
9+
10+
gs.print("=== Duplicate Ticket Numbers in " + tableName + " ===");
11+
while (ga.next()) {
12+
var ticketNumber = ga.getValue("number");
13+
var count = ga.getAggregate("COUNT", "number");
14+
gs.print("Number: " + ticketNumber + " | Count: " + count);
815
}

0 commit comments

Comments
 (0)