Variables & Helper Methods
Complete reference for slash command variables and helper methods available in custom URL and Script commands.
Last updated: February 17, 2026
Last updated: February 17, 2026
This page documents all placeholders and helper methods that can be used in custom slash commands.
| Variable | Meaning | Example Input | Output |
|---|---|---|---|
$0 | Entire text after the command name | /inc vpn issue | vpn issue |
$1, $2, ... | Space-separated tokens from $0 | /inc vpn issue | $1 = vpn, $2 = issue |
$date | Today's date in YYYY-MM-DD format | /lgbet 08:00 09:00 | 2026-03-18 |
| Variable | Meaning | Notes |
|---|---|---|
$table | Current table name | Resolved from form, list, workspace, portal, Studio and supported builders |
$sysid | Current record sys_id | Resolved when a current record context exists |
$encodedquery | Current list/filter encoded query | Available when the context exposes query/filter information |
When a command returns inline results and you configure fields, you can reference those fields in Overwrite target URL:
| Pattern | Meaning |
|---|---|
$fieldname | Value of that field on the selected row |
Example:
Overwrite target URL: /now/builder/ui/${admin_panel.sys_id}
(Using the actual placeholder style from slash commands: $admin_panel.sys_id.)
| Variable | Meaning |
|---|---|
$ext/ | SN Utils extension asset base URL |
Example:
$ext/html/settingeditor.html?setting=slashcommand_legacy
Script commands run in the page context, so you can call SN Utils helper methods directly.
snuGetGForm()Returns a unified g_form reference across classic UI and supported workspace scenarios when available.
const form = snuGetGForm();
if (form) {
const table = form.getTableName();
const sysId = form.getUniqueValue();
console.log(table, sysId);
}
snuGetDocument()Returns the active content document (iframe-aware), useful when the rendered UI is inside gsft_main.
const doc = snuGetDocument();
const title = doc.querySelector('title')?.textContent;
console.log(title);
snuGetWindow()Returns the active content window (iframe-aware), useful for APIs scoped to the content frame.
const win = snuGetWindow(); console.log(win.location.href);
snuShowAlert(msg, type, timeout)Displays a banner notification at the top of the page. Supports multiple concurrent banners, auto-close, and manual dismissal. The message is prefixed with "SN Utils:" automatically.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
msg | string | — | The message to display. Supports HTML content. |
type | string | 'info' | Banner style: 'success', 'info', 'warning', or 'danger'. |
timeout | number | 3000 | Auto-close delay in milliseconds. Pass 0 to keep the banner visible until manually closed. |
Returns the banner HTMLElement. Call banner._snuClose() to dismiss it programmatically.
Show a success notification
snuShowAlert('Record updated successfully', 'success');
Show a persistent warning
snuShowAlert('Check failed — review the logs', 'warning', 0);
Dismiss programmatically
const banner = snuShowAlert('Processing…', 'info', 0);
// … later …
banner._snuClose();
snuShowModal(options)Shows a styled modal dialog with optional title, body content, input fields, and custom buttons. Returns a Promise that resolves when the user clicks a button or dismisses the modal. Replaces the need for native alert() / confirm() / prompt() and hand-built DOM.
Parameters
The options object accepts:
| Property | Type | Default | Description |
|---|---|---|---|
title | string | '' | Optional header text (supports HTML, sanitized). |
body | string | '' | Body content (supports HTML, sanitized). |
inputs | array | [] | Input field definitions (see below). |
buttons | array | [{ label: 'OK', value: 'ok', style: 'primary' }] | Button definitions. |
size | string | 'medium' | Dialog width: 'small', 'medium', or 'large'. |
Each input object:
| Property | Type | Description |
|---|---|---|
name | string | Key used in the returned inputs object. |
label | string | Label displayed above the field. |
placeholder | string | Placeholder text. |
value | string | Pre-filled value. |
type | string | 'text' (default), 'textarea', or 'select'. |
options | array | For type: 'select' — array of strings or { label, value } objects. |
Each button object:
| Property | Type | Description |
|---|---|---|
label | string | Button text. |
value | string | Value returned when this button is clicked. |
style | string | 'primary', 'secondary', or 'danger'. |
Returns a Promise that resolves to { button, inputs } or null if dismissed via backdrop click or Escape.
Simple alert replacement
await snuShowModal({ body: 'Record saved successfully.' });
Confirm with custom buttons
const result = await snuShowModal({
title: 'Confirm deletion',
body: 'This will permanently delete the record.',
buttons: [
{ label: 'Cancel', value: 'cancel', style: 'secondary' },
{ label: 'Delete', value: 'delete', style: 'danger' }
]
});
if (result?.button === 'delete') {
// proceed with deletion
}
Modal with input fields
const result = await snuShowModal({
title: 'Create incident',
inputs: [
{ name: 'short_description', label: 'Short description', placeholder: 'Describe the issue...' },
{ name: 'urgency', label: 'Urgency', type: 'select', options: ['Low', 'Medium', 'High'] }
],
buttons: [
{ label: 'Cancel', value: 'cancel', style: 'secondary' },
{ label: 'Create', value: 'create', style: 'primary' }
]
});
if (result?.button === 'create') {
console.log(result.inputs.short_description, result.inputs.urgency);
}
snuConfirm(message, options)Convenience shorthand for a styled confirm dialog. Returns a Promise that resolves to true (confirmed) or false (cancelled / dismissed).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
message | string | — | The question to display. |
options | object | {} | Optional confirmLabel and cancelLabel strings. |
const ok = await snuConfirm('Delete these 5 records?');
if (!ok) return;
// With custom button labels:
const ok = await snuConfirm('Apply the update?', {
confirmLabel: 'Update',
cancelLabel: 'Back'
});
snuPrompt(message, defaultValue)Convenience shorthand for a styled single-input prompt. Returns a Promise that resolves to the entered string, or null if the user cancelled.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
message | string | — | The label / question to display. |
defaultValue | string | '' | Pre-filled input value. |
const name = await snuPrompt('Enter group name:', 'New Group');
if (name === null) return; // user cancelled
console.log('Group name:', name);
snuCopyToClipboard(text, showFeedback)Copies text to the clipboard. Shows a success or error banner automatically unless feedback is disabled.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | string | — | The text to copy. |
showFeedback | boolean | true | Show a success/error banner. Pass false for silent operation. |
Returns a Promise that resolves to true on success, false on failure.
await snuCopyToClipboard('INC0012345');
// Silent copy (no banner):
await snuCopyToClipboard(someData, false);
snuGetSelectedRecords()Returns the sys_ids of the checked (selected) rows in the current list view. Returns an empty array when no rows are selected or when not on a list page.
const ids = snuGetSelectedRecords();
if (!ids.length) {
snuShowAlert('Select records first', 'warning');
return;
}
console.log('Selected:', ids);
snuGetRecordContext()Simplified wrapper around snuResolveVariables() that returns a clean context object with table, sysId, and encodedQuery properties.
const ctx = snuGetRecordContext();
if (ctx.table && ctx.sysId) {
console.log('Viewing ' + ctx.table + ' / ' + ctx.sysId);
}
snuCodeSearch(query)Opens the Code Search page with the given query. Supports all GraphQL search syntax (table:, field:, "quoted phrases"). In classic mode, table: will filter to matching tables in the search group.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
query | string | '' | The search query to pass to Code Search. |
Basic code search
snuCodeSearch('GlideRecord');
Search a specific table and field
snuCodeSearch('table:sys_script_include field:script "getValue"');
Custom command shortcut for code search
Create a Script command that combines pre-filled filters with the user's search term:
snuCodeSearch('table:sys_script table:sys_properties field:script "GlideRecord" ' + '$0');
Running /mycommand addQuery will open code search with: table:sys_script table:sys_properties field:script "GlideRecord" addQuery
snuShowBusy(msg)Shows a persistent banner with an animated spinner. Use it to indicate long-running operations. Call _snuClose() on the returned element when the work is done.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
msg | string | 'Working…' | Message shown next to the spinner. |
Returns the banner HTMLElement. Call banner._snuClose() to dismiss.
const busy = snuShowBusy('Updating records...');
for (const id of ids) {
await snuFetchData(g_ck, '/api/now/table/incident/' + id,
{ method: 'PATCH', body: { state: '6' } }, null);
}
busy._snuClose();
snuShowAlert('Done!', 'success');
You can also use the 'loading' type directly with snuShowAlert:
const banner = snuShowAlert('Processing…', 'loading', 0);
// ... async work ...
banner._snuClose();
snuResolveVariables(variableString)Resolves $table, $sysid, $encodedquery and $ext/ placeholders in a string against the current page context. It detects the active record by inspecting, in priority order: g_form, report pages, classic lists (GlideList2), Flow Designer, Conversation Builder, ServiceNow Studio / Workflow Studio, Portal query parameters, and Workspace URL paths (including sub-records).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
variableString | string | '' | Optional. The string containing $table, $sysid, $encodedquery or $ext/ placeholders to resolve. When omitted the function only detects context values. |
Returns an object with four properties:
| Property | Type | Description |
|---|---|---|
variableString | string | The input string with all recognised placeholders replaced |
tableName | string | The detected table name (empty string when unavailable) |
sysId | string | The detected record sys_id (empty string when unavailable) |
encodedQuery | string | The detected encoded query (empty string when unavailable) |
Resolve a URL template
const url = snuResolveVariables('/$table.do?sys_id=$sysid').variableString;
window.open(url, '_blank');
Read current context without replacing anything
Pass without variableString to retrieve context values only:
const ctx = snuResolveVariables();
if (ctx.tableName && ctx.sysId) {
console.log(`Viewing ${ctx.tableName} / ${ctx.sysId}`);
}
Build a filtered list URL
const listUrl = snuResolveVariables( '/$table_list.do?sysparm_query=$encodedquery' ).variableString;
incident_list.do?sysparm_query=short_descriptionLIKE$0
incident.do?sys_id=$1
sys_update_version_list.do?sysparm_query=name=$table_$sysid
$ext/html/settingeditor.html?setting=slashcommand_legacy
This command uses $date together with $1 and $2 to open a syslog filtered between two times today. Because all variables are resolved before navigation, no script is needed:
syslog_list.do?sysparm_query=sys_created_onBETWEENjavascript:gs.dateGenerate('$date','$1:00')@javascript:gs.dateGenerate('$date','$2:00')^ORDERBYsys_created_on
Usage: /lgbet 08:34 08:41 opens the syslog list filtered to records created between 08:34 and 08:41 today.
Variables like $0, $1, $2, $date, $table, and $sysid work inside Script commands too. They are substituted in the decoded script before execution, so you can reference them directly as string literals:
// Command: /vdrel
// Opens a related list on the current record in a new tab
const ctx = snuResolveVariables();
if (!ctx.tableName || !ctx.sysId) {
snuShowAlert('Open a record first', 'warning');
} else {
const related = '$0' || 'incident_task';
const url = '/' + ctx.tableName + '.do?sys_id=' + ctx.sysId +
'&sysparm_view=related_list&sysparm_related_list=' + related;
window.open(url, '_blank');
}
This script command uses snuGetSelectedRecords, snuConfirm, and snuFetchData together to update checked rows:
const ids = snuGetSelectedRecords();
if (!ids.length) {
snuShowAlert('Select records first', 'warning');
return;
}
const ok = await snuConfirm('Update ' + ids.length + ' record(s)?');
if (!ok) return;
for (const id of ids) {
await snuFetchData(g_ck,
'/api/now/table/$table/' + id,
{ method: 'PATCH', body: { state: '6' } },
null
);
}
snuShowAlert('Updated ' + ids.length + ' record(s)', 'success');
const query = await snuPrompt('Enter encoded query to copy:');
if (query === null) return;
await snuCopyToClipboard(query);