From 0d5d75ef655e19c208a19a46eb3694e2f5b9d737 Mon Sep 17 00:00:00 2001 From: Ravi Chandra <149189748+ravichandra1998g@users.noreply.github.com> Date: Mon, 13 Oct 2025 12:38:15 +0530 Subject: [PATCH] Revert "GlideFilter Case-Insensitive Search" --- .../Normalize_All_Variants_of_prod.js | 27 ------------ GlideFilter/CaseSensitiveSearch/README.md | 43 ------------------- 2 files changed, 70 deletions(-) delete mode 100644 GlideFilter/CaseSensitiveSearch/Normalize_All_Variants_of_prod.js delete mode 100644 GlideFilter/CaseSensitiveSearch/README.md diff --git a/GlideFilter/CaseSensitiveSearch/Normalize_All_Variants_of_prod.js b/GlideFilter/CaseSensitiveSearch/Normalize_All_Variants_of_prod.js deleted file mode 100644 index 299fb54a0d..0000000000 --- a/GlideFilter/CaseSensitiveSearch/Normalize_All_Variants_of_prod.js +++ /dev/null @@ -1,27 +0,0 @@ -// Create this as fix script or run as background script as per your requirement -(function normalizeProdWithGlideFilter() { - var changeGR = new GlideRecord('change_request'); - changeGR.addNotNullQuery('u_environment'); - var normalizeProdFilter = 'u_environment=prod'; - changeGR.addEncodedQuery(normalizeProdFilter); - changeGR.query(); - - var filter = new GlideFilter(normalizeProdFilter, 'filterCondition'); - filter.setCaseSensitive(false); // Match any case variant of "prod" - filter.setEnforceSecurity(true); // Enforce ACLs - - var updated = 0; - - while (changeGR.next()) { - if (filter.match(changeGR, true)) { - var original = changeGR.u_environment.toString(); - - if (original !== 'Prod') { - changeGR.u_environment = 'Prod'; - changeGR.update(); - updated++; - } - } - } - gs.info('Environment normalization completed. Total updated: ' + updated); -})(); diff --git a/GlideFilter/CaseSensitiveSearch/README.md b/GlideFilter/CaseSensitiveSearch/README.md deleted file mode 100644 index e40859c9f5..0000000000 --- a/GlideFilter/CaseSensitiveSearch/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# ServiceNow Fix Script: Normalize "prod" Environment Using GlideFilter - -## Problem Statement - -In many ServiceNow environments, custom fields like `u_environment` on tables such as `change_request` often contain inconsistent variants of the same logical value, for example: `prod`, `PROD`, `Prod`,`PrOd`, `pRoD` etc. - -These inconsistencies cause: -- Bad or inconsistent reports -- Broken automation rules like BR or flow with condition -- And, Poor data hygiene or dirty values - ---- - -## Solution: Fix Script or Background Script Using GlideFilter - -We use **`GlideFilter`** with **case-sensitive matching** to securely identify inconsistent values to avoid multiple `if` conditions or regular expressions. - ---- - -## Example - -Instead of writing custom logic with if statement like this: - -```javascript -var env = gr.u_environment.toString().toLowerCase(); -if (env === 'prod' || env === 'prod ' || env === 'PROD' || env === 'PrOd') { - // Normalize -} -``` - -You can simply write: -```javascript -var filter = new GlideFilter('u_environment=prod', 'envNormalize'); -filter.setCaseSensitive(false); -if (filter.match(gr, true)) { - // Normalize -} -``` - -## **How to Use** -1. Go to **Scripts - Background** or **Fix Scripts**. -2. Define the script using above glidefilter example shared. -3. Click **Run Script**.