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". We can name the variable different names, but we must always prefix the variable with jvar for it to work.

Here, we are setting jvar_variable to the string value in the script. In an evaluate tag, we just need to make the last line of our expression the variable we want to set the evaluate variable to. In our example, we have used setVariable, so jvar_variable becomes the value of setVariable, which is our string.

There are some parameters we can use in a <g:evaluate> tag; let's see these used in another example:

<g2:evaluate var="jvar_onHoldIncidents" object="true" jelly="true">
var holdIncident = new GlideRecord('incident');
holdIncident.addQuery('state', jelly.jvar_onHoldState);
holdIncident.query();
holdIncident;
</g2:evaluate>

In this example, we can see two new parameters for the <g:evaluate> tag: object and jelly. The object tag dictates whether the jvar variable should be treated as an object. For our example, it would be the GlideRecord query, and so we would want this held as an object for later scripting. 

The other new parameter is jelly. This parameter, if set to true, allows us to use jelly variables in our script. For our example, we are using the jvar_onHoldState variable, which we are assuming has been set to 3 in a previous <g:evaluate> tag. We need the jelly parameter set to true so we can use this variable in our example script.

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

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