From 47086c2fef2e8c599c4f27fb1ce60a75149886a4 Mon Sep 17 00:00:00 2001 From: Lucifer <108731648+shivamvish160@users.noreply.github.com> Date: Fri, 17 Oct 2025 21:49:53 +0530 Subject: [PATCH 1/2] Create README.md --- .../Script Include Usage Tracker/README.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Server-Side Components/Script Includes/Script Include Usage Tracker/README.md diff --git a/Server-Side Components/Script Includes/Script Include Usage Tracker/README.md b/Server-Side Components/Script Includes/Script Include Usage Tracker/README.md new file mode 100644 index 0000000000..bab5c5143f --- /dev/null +++ b/Server-Side Components/Script Includes/Script Include Usage Tracker/README.md @@ -0,0 +1,21 @@ +# Script Include Usage Tracker + +A utility Script Include to help ServiceNow developers identify where a specific Script Include is being referenced across the instance. This is especially useful during refactoring, cleanup, or impact analysis. + +## Features + +- Scans multiple tables for references to a given Script Include. +- Outputs a list of locations including table name, record name, and sys_id. +- Easily extendable to include more tables or fields. + +## Installation + +1. Navigate to **System Definition > Script Includes** in your ServiceNow instance. +2. Click **New** and paste the code from `ScriptIncludeUsageTracker.js`. +3. Save and make sure the Script Include is **Client Callable = false**. + +## Usage + +You can run the Script Include from a background script or another Script Include like this: +var tracker = new ScriptIncludeUsageTracker(); +tracker.findUsage('MyScriptInclude'); From f988e5ae9cf84e022f7aec771e6f72b5f8b1a820 Mon Sep 17 00:00:00 2001 From: Lucifer <108731648+shivamvish160@users.noreply.github.com> Date: Fri, 17 Oct 2025 21:50:51 +0530 Subject: [PATCH 2/2] Create code.js --- .../Script Include Usage Tracker/code.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Server-Side Components/Script Includes/Script Include Usage Tracker/code.js diff --git a/Server-Side Components/Script Includes/Script Include Usage Tracker/code.js b/Server-Side Components/Script Includes/Script Include Usage Tracker/code.js new file mode 100644 index 0000000000..a46436a009 --- /dev/null +++ b/Server-Side Components/Script Includes/Script Include Usage Tracker/code.js @@ -0,0 +1,35 @@ + + + var scriptIncludeName = 'MyScriptInclude'; // Change this to your target Script Include + var usage = []; + + function searchUsage(table, field) { + var gr = new GlideRecord(table); + gr.addEncodedQuery(field + 'LIKE' + scriptIncludeName); + gr.query(); + while (gr.next()) { + usage.push({ + table: table, + name: gr.name || gr.getDisplayValue(), + sys_id: gr.getUniqueValue() + }); + } + } + + var tablesToSearch = [ + { table: 'sys_script', field: 'script' }, + { table: 'sys_ui_action', field: 'script' }, + { table: 'sys_script_include', field: 'script' }, + { table: 'sys_flow_context', field: 'definition' }, + { table: 'sys_trigger', field: 'script' } + ];// can add more entries here + + tablesToSearch.forEach(function(t) { + searchUsage(t.table, t.field); + }); + + gs.info('Usage of Script Include: ' + scriptIncludeName); + usage.forEach(function(u) { + gs.info('Found in table: ' + u.table + ', name: ' + u.name + ', sys_id: ' + u.sys_id); + }); +