Namespaces and phases

Just like any language based on XML, Apache Jelly includes multiple namespaces. The xmlns:j is used for Jelly, whereas the xmlns:g is used to include the Glide namespace. When referring to tags within Jelly and glide namespaces, we only use the prefixes j and g respectively. There are two other namespaces available: xmlns:j2 and xmlns:g2. These usually represent the phase of the script, where we either use <j> versus <j2>and <g> versus <g2>.

All Jelly script in ServiceNow will start with the following line of code:

<j:jelly trim= "false" xmlns:j= "jelly:core" xmlns:g= "glide" xmlns:j2= "null" xmlns:g2= "null" > 

In the preceding script, we include jelly:core and glide namespaces, and they will be referred to the script using the j and g prefixes respectively. The j prefix is used for tags that are native to Apache Jelly, whereas the g prefix is used for tags that ServiceNow platform extended and included in the platform. Similarly, the j2 and g2 prefixes are like j and g; however, they are processed only in the second phase:

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> 
<j:setvar="jvar_message" value="Hello" /> 
<j2:setvar="jvar_name" value="Sagar Gupta" /> 
${jvar_message} $[jvar_name]  
</j:jelly> 

In the preceding code, we have used the j:set and j2:set tags. The code will be parsed and executed twice in two different phases, namely phase I and phase II. Furthermore, variables in phase I are enclosed in curly brackets prefixed with a dollar sign, such as ${jvar_variable_1}, and in phase II are enclosed in square brackets prefixed with a dollar sign, such as $[jvar_variable_2].

The j:set tag, along with the ${jvar_message}, will evaluate in phase I, and the code will be cached for all subsequent calls to this script. The cached code for phase II will appear to the system like the one shown here:

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="jelly:core" xmlns:g2="glide"> 
<j2:setvar="name" value="Sagar Gupta" /> 
Hello $[jvar_name] 
</j:jelly> 

Note that in the preceding code, the j:set tag and ${jvar_message} have already evaluated and are not part of the phase II code. Only j2 and g2 tags, along with the variables enclosed in $[jvar_square_brackets], are available for subsequent execution.

Let us now go through some of the Jelly and Glide tags.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.15.94