Skip to content
Merged
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
@@ -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');
Original file line number Diff line number Diff line change
@@ -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);
});

Loading