GlideEvaluator - evaluateScript(GlideRecord grObj, String scriptField, Object variables)

Evaluates a script from a GlideRecord field.

Table 1. Parameters
Name Type Description
grObj GlideRecord The GlideRecord containing a script expression.
scriptField String (Optional) The name of the field containing the script expression.
variables Object (Optional) A map of variables with name-value pairs. These variables are available to the script during execution of this method.
Table 2. Returns
Type Description
Object The result of the script execution.

Scoped equivalent

To use the evaluateScript() method in a scoped application, use the corresponding scoped method: Scoped GlideEvaluator - evaluateScript(GlideRecord grObj, String scriptField, Object variables).

// For this example, we created a table: "u_global_table" with two columns: "short_description", "test_script"
// "test_script" will store the script to be evaluated by GlideScopedEvaluator.
gr = new GlideRecord('u_global_table'); 
gr.u_short_description = 'Testing GlideScopedevaluator';  
gr.u_test_script = "gs.getUser().getName() + ' says ' + greeting; "; 
// setup variables to be used by the script
var vars = {'greeting' : 'hello'};
//Evaluate the script from the field
var evaluator = new GlideScopedEvaluator(); 
gr = new GlideRecord('u_global_table'); 
gr.addQuery('u_short_description','Testing GlideScopedevaluator'); 
if ( {, 'u_test_script', vars));

Output: admin says hello