From e30ec07292de65e368dbf4658aacc0bb084a1543 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2025 14:14:11 +0200 Subject: [PATCH] Delete Server-Side Components/Background Scripts/Find out Duplicate Records directory This is a duplicate of https://github.com/WillemZeiler/code-snippets/tree/main/Server-Side%20Components/Background%20Scripts/Duplicate%20Finder removing this duplicate as the one in the link is an updated version (updated + expanded yesterday). This change deletes: - The folder "Find out Duplicate Records". - Duplicate Records for any table.js - Duplicate Records.js - Readme.md --- ...te Records for any table based on field.js | 37 ------------------- .../Duplicate Records.js | 8 ---- .../Find out Duplicate Records/README.md | 7 ---- 3 files changed, 52 deletions(-) delete mode 100644 Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records for any table based on field.js delete mode 100644 Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records.js delete mode 100644 Server-Side Components/Background Scripts/Find out Duplicate Records/README.md diff --git a/Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records for any table based on field.js b/Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records for any table based on field.js deleted file mode 100644 index 42b71aaee2..0000000000 --- a/Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records for any table based on field.js +++ /dev/null @@ -1,37 +0,0 @@ -// Function to check for duplicates in a specified field of a given table -function DupCheck(table, field) { - var arr = []; - var gr = new GlideAggregate(table); - - // Aggregate count of the specified field and group by it - gr.addAggregate('COUNT', field); - gr.groupBy(field); - gr.addHaving('COUNT', '>', 1); - gr.query(); - - gs.info("Please find the duplicates from the " + table + " for the field " + field + " below:"); - - // Loop through each group with duplicate counts - while (gr.next()) { - var duplicateValue = gr.getValue(field); - var kb = new GlideRecord(table); - - // Query for active records matching the duplicate value - kb.addQuery(field, duplicateValue); - kb.addQuery('active', 'true'); - kb.query(); - - // Collect and log the duplicates - while (kb.next()) { - arr.push(kb.sys_id.toString()); - gs.info('--> Number: {0}, and its Sys ID: {1}', [kb.number, kb.sys_id]); - } - } - - // Optionally return the array of sys_ids for further processing - gs.info("array of sys_id's : " + arr); - return arr; -} - -// Call the function to check for duplicates in the incident table -DupCheck("kb_knowledge", "short_description"); \ No newline at end of file diff --git a/Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records.js b/Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records.js deleted file mode 100644 index 84996f56e8..0000000000 --- a/Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records.js +++ /dev/null @@ -1,8 +0,0 @@ -var gr = new GlideAggregate(incident); -gr.addAggregate('COUNT', number); -gr.groupBy(number); -gr.addHaving('COUNT', '>', 1); -gr.query(); -while (gr.next()) { - gs.print(gr.getValue(number) + ' has ' + gr.getAggregate('COUNT', field) + ' duplicate records '); -} diff --git a/Server-Side Components/Background Scripts/Find out Duplicate Records/README.md b/Server-Side Components/Background Scripts/Find out Duplicate Records/README.md deleted file mode 100644 index 9c2a116fc1..0000000000 --- a/Server-Side Components/Background Scripts/Find out Duplicate Records/README.md +++ /dev/null @@ -1,7 +0,0 @@ -This script helps to find out duplicate records in the table and returns an array of the duplicate records sys_id's. - -In this example I have shown how to find out records in knowledge table. - -All you need to do is use the call the function with the table and field values as shown below: -DupCheck("kb_knowledge", "short_description"); -where "DupCheck" is the function, "kb_knowledge" is the table name and "short_description" is the field based on which your duplicates will be found. \ No newline at end of file