Variables & Helper Methods

Complete reference for slash command variables and helper methods available in custom URL and Script commands.

This page documents all placeholders and helper methods that can be used in custom slash commands.

Variable Reference

Input Variables

VariableMeaningExample InputOutput
$0Entire text after the command name/inc vpn issuevpn issue
$1, $2, ...Space-separated tokens from $0/inc vpn issue$1 = vpn, $2 = issue

Context Variables

VariableMeaningNotes
$tableCurrent table nameResolved from form, list, workspace, portal, Studio and supported builders
$sysidCurrent record sys_idResolved when a current record context exists
$encodedqueryCurrent list/filter encoded queryAvailable when the context exposes query/filter information

Inline Result Variables

When a command returns inline results and you configure fields, you can reference those fields in Overwrite target URL:

PatternMeaning
$fieldnameValue 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.)

Extension Variable

VariableMeaning
$ext/SN Utils extension asset base URL

Example:

$ext/html/settingeditor.html?setting=slashcommand_legacy

Helper Methods for Script Commands

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);

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

NameTypeDefaultDescription
variableStringstring''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:

PropertyTypeDescription
variableStringstringThe input string with all recognised placeholders replaced
tableNamestringThe detected table name (empty string when unavailable)
sysIdstringThe detected record sys_id (empty string when unavailable)
encodedQuerystringThe 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;

Practical Examples

Open filtered incidents by full input

incident_list.do?sysparm_query=short_descriptionLIKE$0

Open specific record by tokenized input

incident.do?sys_id=$1

Reuse current context

sys_update_version_list.do?sysparm_query=name=$table_$sysid

Jump to extension-managed page

$ext/html/settingeditor.html?setting=slashcommand_legacy

Notes

  • If a context variable cannot be resolved in the current page, it resolves to an empty string.
  • Prefer URL commands for simple navigation and filtering.
  • Use Script mode only when you need conditional logic or DOM/API interaction.