Custom Commands
Create your own SN Utils slash commands with custom searches, URL templates, and context menu integration.
Last updated: January 24, 2026
Last updated: January 24, 2026
Custom commands let you turn repeated ServiceNow navigation, searches, and small page scripts into short slash commands that work across your instances. The main editor lives in Manage > Commands (open it with the popup gear icon or /manage), and /newcmd can start a new command directly from the slash palette.
Modern custom commands are edited through the form UI so names, URLs, fields, sharing, and sync stay predictable. Legacy pre-v10 JSON commands remain supported separately under Manage > Advanced > Legacy JSON Editing.
Let's create a custom incident search command:
/incident -fNumber CONTAINS $0 Or Short Description CONTAINS $0/manage) and go to the Commands tabincnumber,short_descriptionTest with /inc sap and Right Arrow — you'll see results with number and short description fields. This command works across all your instances!
/newcmd)You don't have to leave the page you're on. Open the slash palette and type /newcmd to jump straight to the Commands tab with the editor in the "new" state, focused on the command name. Add a description after the shortcut and /newcmd will sniff what you typed and prefill the right field:
| What you type | Where it lands |
|---|---|
URL or path — incident_list.do?sysparm_query=active=true, /sp?id=..., https://... | URL field (URL mode) |
Script — javascript:alert(g_form.getTableName()) or (function(){…})() | Script editor (Script mode, javascript: prefix decoded) |
Bare fields list — number,short_description,priority | Fields field |
Encoded query — active=true^priority=1 | URL field as &sysparm_query=active=true^priority=1 |
| Anything else (natural language) | Description field |
Single-token inputs like /newcmd incident are treated as natural language — too ambiguous to assume "this is a table name" — so they land in the description.
If your input is natural language and you're on Pro, the AI Builder opens and runs the prompt for you with the current page as context — review and Save. On Community the description is prefilled into the editor so you have a starting point for writing the command yourself.
Examples:
/newcmd sys_user_list.do?sysparm_query=nameLIKE$0 — URL command, ready to name and save./newcmd javascript:g_form.save() — bookmarklet → script command in Monaco./newcmd number,short_description,assigned_to — fields list to attach to whatever URL you set./newcmd open the caller's user record in a new tab (Pro) — AI generates the command with page context.The Commands tab on the Manage page is where you create, edit, and manage all your slash commands.
$0, $sysid, $table, $encodedquery, $ext/, and inline result fieldsMost commands are URL commands. They open a ServiceNow path, absolute URL, or another slash command alias and can include variables such as $0, $table, or $sysid.
Use Script commands when the command should run JavaScript on the current ServiceNow page. Script mode uses Monaco, auto-minifies the saved action, and can call SN Utils helpers such as snuGetGForm(), snuShowModal(), and snuCodeSearch().
If you paste a javascript: bookmarklet, the editor switches to Script mode and decodes the script for editing. See Variables & Helper Methods for the full helper reference.
Custom commands are available in the form-based Commands tab. Pro features such as cloud sync, Team Space sharing, and AI-assisted generation build on top of the same command format.
Command names should stay short and URL-safe. For cloud sync, use at least one letter or number and only letters, digits, _, -, or modifier punctuation such as ?, !, ., +, :, @, #, ~, ^, =. Unsupported names can be saved locally, but they will not sync until renamed.
| Variable | Description |
|---|---|
$0 | Search term |
$1, $2... | Individual words from the search term |
$date | Today's date (YYYY-MM-DD) |
$sysid | Current record sys_id |
$table | Current table name |
$TableName | PascalCase form of the current table name for use as a JS identifier (e.g. incident → Incident, sys_user → SysUser). Falls back to Record when no table is in scope |
$encodedquery | Current list/filter encoded query (when available) |
$fieldname | Value from inline result fields |
$ext/ | SN Utils extension asset base URL |
Need the full reference with examples and script helpers?
See: Variables & Helper Methods
Some commands filter records but should open a different page. Use "Overwrite target URL" for this.
Example: The /uibe command searches experiences but opens UI Builder directly:
sysparm_query= — Recognized as table filtering commandadmin_panel.sys_id) available for target URL$admin_panel.sys_idRunning /uibe util:
You can create custom commands that open Code Search with pre-filled filters, so you don't need to type the same table: and field: syntax every time.
snuCodeSearch() (recommended)Create a Script command that calls the snuCodeSearch() helper with your preferred filters plus $0 for the user's search term:
codebr for Business Rules)snuCodeSearch('table:sys_script field:script ' + '$0');
Now /codebr GlideRecord opens Code Search filtered to sys_script records containing "GlideRecord" in the script field.
You can combine multiple tables and fields:
snuCodeSearch('table:sys_script table:sys_properties field:script "GlideRecord" ' + '$0');
//code alias (alternative)You can also use the // URL prefix to alias the built-in /code command:
codebr)//code table:sys_script field:script $0This expands /codebr mySearch into /code table:sys_script field:script mySearch.
/codecurrentThere's also a built-in /codecurrent command that automatically pre-fills Code Search with the current table context. On a sys_script_include form, /codecurrent getValue searches for "getValue" filtered to the sys_script_include table.
See also: snuCodeSearch() in the helper methods reference.
Add #contextmenu to a command's URL to make it available in the right-click context menu:
After saving:
Custom switches have their own dedicated Switches tab on the Manage page. Start with the guide: Slash Switches.
Advanced examples are also available on the Switches page.
Commands created before the form-based editor remain editable as raw JSON under Manage > Advanced > Legacy JSON Editing — and only there. Modern custom commands have no raw-JSON path by design; they live on the form-based Commands tab so inputs stay validated and cloud sync stays predictable.
See Legacy JSON Editing for the full workflow, the Convert-to-Custom flow that migrates grandfathered entries into the modern format, and the automatic local snapshots captured before every save.