Custom commands
Your own palette commands, with variables that fill in from what you type and the page you are on.
A custom command is a name and a target. Type the name in the palette and it opens the target: a list with a query, a page, a URL, or another command.
Making one
Type /newcmd and press Enter. A form opens with:
- Name: what you type after
/to run it. Letters, digits and-, starting with a letter. - Kind: Table, URL or Alias, each with its own fields.
- Variables: chips you click to put a variable where the cursor is.
- Try with: text to test with, and a line under it showing where the command would go with that text, or why it could not.
Opened from a list, the form starts on that list's table and filter. Opened from a record, it starts on the record's table. Enter saves, Esc closes.
If you already know the syntax, one line does the same:
/newcmd inc incident?numberLIKE$0
The three kinds
| Kind | Target | Opens |
|---|---|---|
| Table | incident?active=true | The list of that table, with that query. The query is optional |
| URL | https://… or /sys.scripts.do | That address. One starting with / is a page on the instance you are on |
| Alias | //br $0 -a | Another command, with those arguments |
A saved query is kept exactly as you wrote it, conditions and all.
Variables
A target can hold variables. They are filled in when the command runs, from what you type after its name and from the page you run it on.
| Variable | Is |
|---|---|
$0 | Everything typed after the command |
$1 … $9 | The words typed after it, one each |
$table | The table of the list or record open |
$sysid | The record open |
$encodedquery | The filter of the list open |
$date | Today, as YYYY-MM-DD |
If a variable has no value, the command stops and says why instead of opening something else.
/inc with nothing after it says /inc needs text after it ($0), where it would otherwise have
opened every incident.
Search by what you type. incident?numberLIKE$0: /inc 10042 opens the incidents whose number
contains 10042.
Two values in two places. incident?priority=$1^assignment_group.nameLIKE$2: /ip 1 network
opens priority 1 incidents of the network group.
The same command on any table. $table?sys_created_by=javascript:gs.getUserName(): on the
incident list it opens your incidents, on the problem list your problems.
From a record to what hangs off it. sc_task?request_item=$sysid: on a requested item it opens
its tasks. On a list, or on a record not saved yet, it stops and asks you to open a saved record.
Your filter, and a bit more. $table?$encodedquery^active=true: the list you are looking at,
with its filter kept and only active records.
$date is the date on your computer, not in your ServiceNow profile's time zone. Around midnight
the two can disagree. For a query, the platform's own ONToday and relative conditions are usually
the better choice.
The variables read the page the same way in the classic UI, inside the Next Experience shell and on a Workspace record.
What you type cannot change the command
Inside a query, text you type loses its ^, so /inc x^ORactive=false searches for that text
instead of adding a condition. Inside a URL it is encoded, so a&b stays one value instead of
becoming a second parameter. $encodedquery is the exception: it is the list's own filter, so it
goes in whole.
Aliases
//name args runs another command, built-in or yours, with those arguments. Variables in the
arguments are filled in first, so //br $0 -a makes a shorter /br that always adds -a.
An alias is refused when you save it if the command it names does not exist, if it names itself, if aliases call each other in a circle, or if more than three aliases lead into each other.
Finding, editing, deleting
| Command | Does |
|---|---|
/cmds | Lists your commands with what each one opens. Pick one to run it |
/newcmd <name> | Opens that command in the form, to change it |
/delcmd <name> | Deletes it. It leaves the palette at once, in every frame |
A command can also be saved from a list: double-click the empty part of the filter strip above it, then Save as command. It opens that list with that query.
A name a built-in command already has is refused, so a custom command never hides one.
Where they live
Custom commands belong to your profile and sync with it. There is
room for 60. /export copies them to the clipboard and /import reads them back. They cannot be
published to the shelf: a command shows a name, not what it opens.
Every custom command takes -it to open in an in-page tab, like the
built-in ones.
