GlideEvaluator - putVariable(String name, Object value)

Puts a variable into the GlideScopedEvaluator object. These variables are available to the script that this GlideScopedEvaluator object runs.

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

Scoped equivalent

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

//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