From 01413181ed19203c67ecef0d1c677af80bbd4e7e Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Wed, 1 Oct 2025 18:52:03 +0530 Subject: [PATCH 1/2] 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. --- .../Get Duplicate/script.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Server-Side Components/Background Scripts/Get Duplicate/script.js b/Server-Side Components/Background Scripts/Get Duplicate/script.js index 4ebdc39422..3ca918a4ab 100644 --- a/Server-Side Components/Background Scripts/Get Duplicate/script.js +++ b/Server-Side Components/Background Scripts/Get Duplicate/script.js @@ -1,8 +1,15 @@ -var dpchk = new GlideAggregate('task'); -dpchk.groupBy('number'); -dpchk.addHaving('COUNT', '>', 1); -dpchk.query(); -while(dpchk.next()) -{ - gs.print(dpchk.number); +// Table to check (e.g., task, incident, change_request) +var tableName = "task"; + +var ga = new GlideAggregate(tableName); +ga.addAggregate("COUNT", "number"); // Count how many times each number appears +ga.groupBy("number"); // Group records by number +ga.addHaving("COUNT", ">", 1); // Only show duplicates +ga.query(); + +gs.print("=== Duplicate Ticket Numbers in " + tableName + " ==="); +while (ga.next()) { + var ticketNumber = ga.getValue("number"); + var count = ga.getAggregate("COUNT", "number"); + gs.print("Number: " + ticketNumber + " | Count: " + count); } From afc1026bae3e31d25a67e2ae5bd9ed048ccb4404 Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Wed, 1 Oct 2025 18:53:05 +0530 Subject: [PATCH 2/2] Update README.md --- .../Background Scripts/Get Duplicate/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Server-Side Components/Background Scripts/Get Duplicate/README.md b/Server-Side Components/Background Scripts/Get Duplicate/README.md index 23de281b78..dac606a043 100644 --- a/Server-Side Components/Background Scripts/Get Duplicate/README.md +++ b/Server-Side Components/Background Scripts/Get Duplicate/README.md @@ -1,3 +1 @@ -Using GlideAggregate function to find out tickets (tasks) with same number. OOB there happens to be a Unique checkbox at dictionary level -and if in case not set to True it might create duplicate numbered tickets. -Script will help find, ticekts if any. +This script identifies duplicate tickets or tasks in ServiceNow when the number field is not unique. It uses GlideAggregate to group records by number, count duplicates, and optionally list affected records with their Sys IDs and short descriptions. Helps maintain data integrity and accurate reporting.