Script Runner
Run a background script in any application, including store apps, from a page hosted by SN Utils. See output, values next to your code, changed records, logs and past runs side by side. Nothing to install on the instance.
Last updated: November 9, 2026
Script Runner
The Script Runner is the instance's own background script, hosted by SN Utils. It runs server-side JavaScript through /sys.scripts.do, exactly like the Scripts - Background page, but it lets you pick any application, including store apps and ServiceNow applications that the instance page leaves out of its list.
Nothing is installed on the instance. Runs appear in the instance's execution history. Record for rollback is available for Global and custom applications that the instance's Scripts - Background page supports.
Opening it
| Command | What it opens |
|---|---|
/bgx | The Script Runner. Text after the command pre-fills the editor, for example /bgx gs.info(gs.getCurrentScopeName()); |
/bgxc | The Script Runner with a GlideRecord for the record you are looking at |
/bgxl | The Script Runner with a GlideRecord loop over the list you are looking at, filter applied, at most 10 rows |
You can also select code in any SN Utils code editor and choose Open in Script Runner... from the context menu. The GlideRecord tab of the SN Utils popup has an Open in Script Runner button.
Open /bg in Script Runner
Open Manage with /manage or the gear icon in the extension popup. Under Settings → Developer Tooling, turn on Open /bg in Script Runner. This setting is off by default; the screenshot shows it enabled.
With this enabled, /bg, /bgc and /bgl open the Script Runner. /bgm always opens the instance's Scripts - Background page, with the SN Utils enhancements of the Better BG Script setting. Reload open ServiceNow tabs after changing the setting.
Choosing the application
The Run in button shows the application the script runs in. It starts on your current application. Click it to search by name or scope. The list is grouped:
- Current application: the application you are working in on the instance.
- Recent: the last few applications you ran in on this instance.
- Global.
- Your applications: custom applications the instance page also lists.
- ServiceNow and store applications: applications the instance page does not list. SN Utils runs your script inside the application with
GlideScopedEvaluator, the documented platform API, from a small global wrapper. The wrapper borrows an existing script record of that application, replaces its script in memory only and never saves it.
A few applications contain no server-side script record at all, such as UI component libraries. A run there reports that and executes nothing.
Choosing an application here never changes the application or update set you are working in.
Running a script
Press Run or Ctrl+Enter (Cmd+Enter on macOS). One press sends exactly one request.
Before every run the Script Runner checks that your session is still valid. If it expired you get a sign-in prompt instead of a half-executed run.
Every script starts with a scope guard. If the instance would run the script in a different application than the one you chose, the guard stops it before your first statement.
For applications supported by the instance's Scripts - Background page, Run adds only that guard line. Other applications use the evaluator wrapper described above. If your script starts with "use strict", the added line keeps it strict. If the start of a script cannot be read with certainty, nothing is sent and the Script Runner says so. Press the eye button to see the exact text before it runs, or script as sent in the status line afterwards. A script that still contains what SN Utils added, for example pasted from script as sent or the instance's execution history, is not run: Remove the added code restores what you typed, as one step you can undo.
Record for rollback is on by default for global and your own applications, as on the instance page. Runs in ServiceNow and store applications do not record a rollback.
Reading the result
Editor and results sit side by side. Use the layout button in the toolbar to stack them instead; the choice is remembered. Drag the divider to resize, double-click it to reset.
- Output shows what the script printed. In an application use
gs.info(),gs.warn()andgs.error();gs.print()is not available there. Use the toolbar to copy or download the output, format JSON, show or hide the*** Script:prefixes, and wrap lines. Atable.sys_idin the output opens the record. A bare sys_id is looked up with/sysidin the tab you opened the Script Runner from. - Inspect (Pro) opens the final value in full, then every value line and line capture, by line. See Values in the code below.
- Records lists what the run inserted, updated or deleted, per table. Click a count to see the records. The link at the top opens the execution history, where you can roll the run back.
- History shows recent background script runs on the instance. Search by script text, then click one to load it into the editor with its application selected. Loading never runs anything, and
Ctrl+Zundoes it.
The status line links to the execution history of the run. If the browser loses the response, the Script Runner says so and links to the history list instead of running the script again.
Errors show the line number of your script. Use Go to line to jump there.
Values in the code (Pro)
Inspect is a preview. In some ServiceNow and store applications, line captures can omit variables or show a record without its fields. A record as the final value can still open its field or table view. Some native date/time and Java values are shown without expanding them.
Press Inspect (Ctrl+Shift+Enter, Cmd+Shift+Enter on macOS) instead of Run to see what values held. Run never does this. Inspect first shows the exact script that will run, with everything SN Utils adds highlighted, and runs only when you confirm.
Inspect stops before running scripts with known calls to insert(), update(), updateMultiple(), deleteRecord() or deleteMultiple(), and tells you the method and line. Use Run for those scripts. Comments and strings do not trigger this check. If the parser cannot check the script, Inspect also stops. This is a guardrail, not a read-only guarantee: aliases, dynamic method names and other scripts can still write. Unrelated methods with these names are also blocked.
Put a value on a line of its own and see what it held, right next to it:
var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.query();
gr.getRowCount() // → 12
while (gr.next()) {
gr.getValue('number') // pass 1/12: → "INC0010001"
}
gr // → incident: no current row
- A value line is a variable, a calculation, or a call that reads, such as
get…(),is…()orhas…(). Lines that act, such asgs.info()orx++, are left alone. - In a loop, up to 20 passes per line are kept: step through them in the Inspect tab with ‹ ›. A GlideRecord capture keeps its current row, and reading it never moves the loop on. A GlideAggregate is not opened as a record cursor; put
getAggregate()in a variable to see the values. - If the script ends with a value, the Inspect tab opens it in full: a tree, up to 50 GlideRecord rows from your own query, or a single record as a list of fields. Copy as JSON copies it.
- The added code reads values and is built not to run your own code: it never runs getters (also of global variables),
toJSONortoStringof your objects, uses retained platform methods only after checking for replacements, keeps the originalgs.printandgs.info, and leaves out password and encrypted fields and anything whose name looks like a secret (password, token, api_key ...), also as the final value and inside objects. Reading a record can still run the instance's own code, such as calculated fields, and the added code makes a run a little slower; use Run when exact behaviour matters. Errors still name your own line numbers. - Inspect keeps the original operations it needs before your script runs. Adding a polyfill does not turn inspection off. A replaced Glide method or an unreadable field type is skipped instead of called.
- Unavailable native metadata affects only the relevant type or field; ordinary objects and arrays remain inspectable. If record and aggregate cursors cannot be distinguished, record views are skipped. Scripts that mention
Proxyare refused; proxies returned by other code cannot always be identified, so use Run for those scripts. - In your own applications, values can only come back through
gs.info(), which also writes them to the system log. Inspect asks for permission first, for that application on that instance only. Global and ServiceNow or store applications never log captured values.
Line captures (Pro)
See what your variables hold on a line, every time the script gets there.
- Click left of a line number, or put the cursor on the line and press
F9. A dot marks the line. - Press Inspect. Run ignores marked lines.
- Open the Inspect tab. Each marked line lists its variables as they were just before the line ran. In a loop, step through the passes with ‹ ›; values that changed since the previous pass are highlighted. The values also show next to the line in the editor.
The script is not paused: a run is one request, so the values are recorded on the way and shown afterwards. Passes recorded before an error are kept.
- Up to 20 lines per run. The first 20 passes per line are kept; the rest are counted.
- A GlideRecord shows its current row only. Capturing never moves a loop on or runs a query.
- A line where no statement starts, such as the middle of an object, cannot be captured. Its marker turns into a ring; hover it to see why.
- Click the dot again to remove it. Editing the script clears the values in the editor.
Logs (Pro)
The Logs tab lists the log lines written during the run, including lines from business rules and script includes the run triggered. Filter by level or text. Lines can take a few seconds to arrive; press Refresh.
Saved scripts (Pro)
Press Ctrl+S (Cmd+S on macOS) or the bookmark button to save the current script with its application. The Saved tab lists your saved scripts. Click one to load it into the editor with its application selected; it does not run. While a saved script is loaded, saving updates it; use Save as new for a copy. Export and Import move your saved scripts as a JSON file.
Saving needs a paid Pro plan. Scripts you saved stay readable and exportable when a license ends, and SN Utils never deletes them.
Script assistant (Pro)
The Assistant tab writes and explains scripts with Sidekick AI. Ask for a script in plain words, or use the shortcuts: Explain the error after a failed run, Explain the output, and Review before running.
- With Apply edits on (the default), the assistant changes the script in the editor straight away, so you can keep refining it in plain words: "only active ones", "add a limit of 10". Each change is one step you can undo with Ctrl+Z, the changed lines are marked, and the chat shows Undo and Show changes. It applies only when the script was sent along (or the editor was empty) and you did not type while the answer came in; otherwise you get Review and use.
- With Apply edits off, a proposed script opens as a side-by-side review first. Replace script puts it in the editor as one undoable step. Insert at cursor adds a snippet where your cursor is, also undoable.
- The assistant never runs anything; you press Run.
- Above the question box you choose what is sent along: the script and the last output. Clear either one to leave it out. The shortcuts respect that choice: if one needs something you left out, it asks whether to include it for that question only.
- New chat starts over, so earlier questions are no longer sent along. The model you pick is shared with Sidekick.
- The assistant follows the Sidekick AI setting and your organization's AI policy. With either turned off, the tab explains how to turn it on.
Good to know
- While a script runs, the browser tab title shows 🔴, then 🟢 or ⚠️ when it finishes.
- The Script Runner keeps the instance and session of the tab you opened it from. Open it again after signing in to a different instance.
- The application list is cached for a day per instance. Use Refresh list at the bottom of the list after installing an application.
- There is no sandbox toggle. Use the instance page with
/bgmwhen you need it.