Evaluate

First, let's have a look at the <g:evaluate> tag. This tag allows us to write JavaScript inside the tag and set a variable value at the end, if required. 

The <g:evaluate> tag is arguably the most used tag in Jelly, and is certainly one to get to grips with. Remember that we can use g or g2 for our tag, depending on which phase we want this script to run in.

Let's have a look at an example of the <g:evaluate> tag in action:

<g2:evaluate var="jvar_variable">     var setVariable = 'Set variable to string';     setVariable;</g2:evaluate>

In the preceding example, we are going to run the code in the second phase, so we are using g2 in the tag we define. In the tag definition, we are also defining a variable name to use with var="jvar_variable" ...

Get Mastering ServiceNow Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.