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 a32469d2a0..0000000000 --- a/Server-Side Components/Background Scripts/Find out Duplicate Records/Duplicate Records for any table based on field.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Function to find duplicate records in any table based on a specified field. - * Returns an array of values from specified output fields for records with duplicate field values. - * - * @param {string} tableName - Name of the table to search. - * @param {string} fieldName - Field to check for duplicates. - * @param {Array} outputFields - Array of field names to include in the output. - */ -function findDuplicateRecords(tableName, fieldName, outputFields) { - var outputValues = []; - - // Count occurrences of the field and group by it (fieldName) - var aggregateGR = new GlideAggregate(tableName); - aggregateGR.addAggregate('COUNT', fieldName); - aggregateGR.groupBy(fieldName); - aggregateGR.addHaving('COUNT', '>', 1); // Corrected HTML entity - aggregateGR.query(); - - // Loop through each group with duplicate values - while (aggregateGR.next()) { - var duplicateValue = aggregateGR.getValue(fieldName); - var recordGR = new GlideRecord(tableName); - - // Query for records with the duplicate value - recordGR.addQuery(fieldName, duplicateValue); - recordGR.addActiveQuery(); // Standard active filter - recordGR.query(); - - // Collect and log duplicate records - while (recordGR.next()) { - var outputEntry = {}; - for (var i = 0; i < outputFields.length; i++) { - var field = outputFields[i]; - outputEntry[field] = recordGR.getValue(field); - } - outputValues.push(outputEntry); - - //optional: log per duplicate record - gs.info('--> Duplicate record: ' + JSON.stringify(outputEntry)); - } - } - - // Log the array of output values - gs.info("Duplicate records: " + JSON.stringify(outputValues)); - - return outputValues; -} - -/** - * === USAGE === - * Customize the table, field to check for duplicate values, and output fields below to run the duplicate check. - */ -findDuplicateRecords("kb_knowledge", "short_description", ["number", "sys_id", "short_description"]); 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 e9fa3c41e7..0000000000 --- a/Server-Side Components/Background Scripts/Find out Duplicate Records/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Duplicate Records Scripts Overview - -# Duplicate Records.js - -This script identifies duplicate values in a specific field of a fixed table (`incident`) and logs how many times each duplicate occurs. - -- Uses `GlideAggregate` to count and group by the `number` field. -- Logs each duplicate record directly to the console. -- Limited to the `incident` table and `number` field. -- No output array is returned; results are only printed. - ---- - -# Duplicate Records for any table based on field.js - -This script finds duplicate records in **any table** based on a specified field and returns an array of values from fields you choose. - -- Uses `GlideAggregate` to detect duplicates and `GlideRecord` to retrieve full record details. -- Function name: `findDuplicateRecords` -- Accepts three parameters: - - `tableName`: the table to search - - `fieldName`: the field to check for duplicates - - `outputFields`: an array of field names to include in the output -- Logs each duplicate record as a structured JSON object. -- Returns a readable array of objects containing the specified output fields.