Skip to content

Commit 58bbbd7

Browse files
authored
Merge pull request #2221 from shivamvish160/usage
Script Include Usage Tracker
2 parents 32e779c + f988e5a commit 58bbbd7

File tree

2 files changed

+56
-0
lines changed
  • Server-Side Components/Script Includes/Script Include Usage Tracker

2 files changed

+56
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Script Include Usage Tracker
2+
3+
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.
4+
5+
## Features
6+
7+
- Scans multiple tables for references to a given Script Include.
8+
- Outputs a list of locations including table name, record name, and sys_id.
9+
- Easily extendable to include more tables or fields.
10+
11+
## Installation
12+
13+
1. Navigate to **System Definition > Script Includes** in your ServiceNow instance.
14+
2. Click **New** and paste the code from `ScriptIncludeUsageTracker.js`.
15+
3. Save and make sure the Script Include is **Client Callable = false**.
16+
17+
## Usage
18+
19+
You can run the Script Include from a background script or another Script Include like this:
20+
var tracker = new ScriptIncludeUsageTracker();
21+
tracker.findUsage('MyScriptInclude');
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
var scriptIncludeName = 'MyScriptInclude'; // Change this to your target Script Include
4+
var usage = [];
5+
6+
function searchUsage(table, field) {
7+
var gr = new GlideRecord(table);
8+
gr.addEncodedQuery(field + 'LIKE' + scriptIncludeName);
9+
gr.query();
10+
while (gr.next()) {
11+
usage.push({
12+
table: table,
13+
name: gr.name || gr.getDisplayValue(),
14+
sys_id: gr.getUniqueValue()
15+
});
16+
}
17+
}
18+
19+
var tablesToSearch = [
20+
{ table: 'sys_script', field: 'script' },
21+
{ table: 'sys_ui_action', field: 'script' },
22+
{ table: 'sys_script_include', field: 'script' },
23+
{ table: 'sys_flow_context', field: 'definition' },
24+
{ table: 'sys_trigger', field: 'script' }
25+
];// can add more entries here
26+
27+
tablesToSearch.forEach(function(t) {
28+
searchUsage(t.table, t.field);
29+
});
30+
31+
gs.info('Usage of Script Include: ' + scriptIncludeName);
32+
usage.forEach(function(u) {
33+
gs.info('Found in table: ' + u.table + ', name: ' + u.name + ', sys_id: ' + u.sys_id);
34+
});
35+

0 commit comments

Comments
 (0)