Jelly tags
-
- UpdatedFeb 1, 2024
- 6 minutes to read
- Washington DC
- API implementation
Use Jelly to turn XML into HTML.
Watch these introductory videos to learn about using Jelly in the ServiceNow AI Platform.
Jelly Tags
- if
- Description: The
if
tag is just what it looks like, anif
tag. This is like anif
statement in any programming language, but keep in mind that there is noelseif
tag and noelse
tag. If you want to create that kind of structure, try thechoose
/when
/otherwise
syntax. - Parameters:
test
- The condition to evaluate in order to determine if the block will execute. - Example:
- Description: The
- while
- Description: The
while
tag does a while loop. - Parameters:
test
- The condition to evaluate in order to determine if the statement will loop through. This should be an expression enclosed in${}
or$[]
that evaluates to true or false. - Example:
- Description: The
- set
- Description: The
set
tag sets a variable. - Parameters:
var
- The variable to set. Often the system prefixes these variables withjvar_
for consistency.value
- The value to setvar
to. This is often an expression enclosed in${}
or$[]
.defaultValue
- If the value results to null or empty, this value is put into thevar
.
- Example:
- Description: The
- set_if
- Description: The
set_if
tag sets a variable based on a test. This tag is similar to theternary
operator in other programming languages (var = <test> ? <if_true> : <if_false>
). - Parameters:
var
- The variable to set. Often the system prefixes these variables withjvar_
for consistency.test
- The condition to evaluate in order to determine if the statement will evaluate the true value or the false value. This should be an expression enclosed in${}
or$[]
that evaluates to true or false.true
- The value to set the variable to iftest
evaluates totrue
. This parameter is optional, so if the field is blank, and if test evaluates to true, the variable is left blank.false
- The value to set the variable to iftest
evaluates to false. This parameter is optional, so if the field is blank, and if test evaluates to false, the variable will be left blank.
- Description: The
- choose
- Description: The
choose
tag starts a choose block of code. This is similar to theif-elseif-else
kind of syntax in most programming languages. With achoose
tag, you can usewhen
andotherwise
tags to specify other blocks of code. - Parameters: None
- Example:
- Description: The
- when
- Description: The
when
tag is used within a choose block to indicate a condition. This tag is similar to anif
or anelseif
in that it specifies a condition, executes the inner content, and then implies a break at the end to leave theif-elseif
construct. - Parameters:
test
- The condition to evaluate in order to determine if the statement will loop through. This should be an expression enclosed in${}
or$[]
that evaluates to true or false. - Example:
- Description: The
- otherwise
- Description: The
otherwise
tag is used within achoose
/when
/otherwise
block, and is like theelse
ordefault
case. - Parameters: None
- Example:
- Description: The
Glide Tags
- evaluate
- Description: The
evaluate
tag evaluates JavaScript code (server side), and makes variables visible to future code. Unlike other tags, theevaluate
tag evaluates the content that is inside the tag as server side JavaScript.The context is the same as that of script includes in the system. Other script includes, global business rules, GlideRecord, GlideSystem, and Jelly variables (prefixed with jelly. if the parameter
jelly="true"
is set) are available. - Parameters:
var
- The name of the variable that will be set to the result of the script.object
- If set totrue
, the result of the expression is treated as an object instead of a primitive variable (string or integer variable values).jelly
- If set totrue
, allows Jelly context variables to be referenced in the script.expression
- This is an expression to be executed for the value to put invar
. The expression can be either of two places. First, it can be an attribute on theevaluate
tag itself. Otherwise, the content between the beginning tag and ending tag is the expression. The last line of the expression is the actual value passed intovar
.
- Example:
- Description: The
- messages
- Description: The
messages
tag helps with translation. When gs.getMessage() is called anywhere on a page, there are two possible places where the translation is found. First, the page checks a local cache of translations. Second, the page makes an AJAX call to the server to find the translation. Whatg:messages
does is allow pages to cache certain messages. - Parameters: None
- Example:
- Description: The
- breakpoint
- Description: When the
breakpoint
tag is called, it prints a list of all the variables in Jelly at the current moment, with their respective values. If a variable is specified, it prints the requested variable and its value. The output is placed in the system log. - Parameters:
var
- (Optional) The variable to log the value for. Ifvar
is not specified, then all variables are dumped into the log. - Example:
- Description: When the
- no_escape
- Description: The system, by default, uses escaped output as a security
measure. Output placed inside of
no_escape
tags is not escaped before output. Be careful when using these tags, because if user input is displayed here it can open a security vulnerability on the page. - Parameters: None
- Example (phase 1) – Disables automatic output escaping of all contained ${} expressions:
- Example (phase 2) – Use
NOESC
to disable escaping for the specified string. This implies the expression must evaluate to a string.For information on phase 1 and phase 2 evaluation, refer to the Jelly introduction videos listed at the beginning of this section.
- Description: The system, by default, uses escaped output as a security
measure. Output placed inside of
- macro_invoke
- Description: The
macro_invoke
tag calls a UI macro that you have specified in the database. You may also call a UI macro by specifying it in the tag name. For example, if you had a UI macro named my_macro, you could call that macro with the tag<g:my_macro/>
. For information, see UI macros. - Parameters:
macro
- The name of the UI macro to execute. If your tag name isg:macro_invoke
, then the macro attribute specifies the name of the macro. If the tag name includes the name of the macro, then there is no need to include a macro attribute.- Other attributes - For each attribute you specify, a variable with that name
will be available in the context of the UI macro, prefixed with
jvar_
.
- Example:
- Description: The
- if_polaris
- Description: The
if_polaris
tag checks if Next Experience is enabled for the current page. It must include at least one of the child tags<g:then />
org:else />
. - Parameters: None
- Example:
- Description: The
- then
- Description: The
then
tag is used within anif_polaris
block to set the page content when Next Experience is enabled. - Parameters: None
- Example:
- Description: The
- else
- Description: The
else
tag is used within anif_polaris
block to set the page content when Next Experience isn't enabled. - Parameters: None
- Example:
- Description: The