GlideEvaluator - getVariable(String name)

Gets a variable from a GlideScopedEvaluator object.

Table 1. Parameters
Name Type Description
name String The name of the variable.
Table 2. Returns
Type Description
Object The value of the specified variable.

Scoped equivalent

To use the getVariable() method in a scoped application, use the corresponding scoped method: Scoped GlideEvaluator - getVariable(String name).

//setting up a record that contains the script to be executed.
gr = new GlideRecord('u_global_table'); 
gr.u_short_description = 'Calculate Addition';  
gr.u_test_script = "result = x + y"; 
gr.insert(); 
 
var evaluator = new GlideScopedEvaluator();
evaluator.putVariable('x', 100);
evaluator.putVariable('y', 200);
evaluator.putVariable('result', null);
 
// Now retrieve the result 
gr = new GlideRecord('u_global_table'); 
gr.addQuery('u_short_description','Calculate Addition'); 
gr.query(); 
if (gr.next()) { 
    evaluator.evaluateScript(gr, 'u_test_script', null);
    gs.info(evaluator.getVariable('result'));
}

Output: 300