Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 14 additions & 7 deletions Server-Side Components/Background Scripts/Get Duplicate/script.js
Original file line number Diff line number Diff line change
@@ -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);
}
Loading