---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideScopedEvaluator - Global

# GlideScopedEvaluator - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read

The GlideScopedEvaluator API allows you to evaluate scripts in a
GlideRecord field from both scoped and global server scripts.

This API evaluates scripts within the script field type. The scope of the record defines the
scope of the script.

## GlideScopedEvaluator - GlideScopedEvaluator() {#ariaid-title2}

Instantiates a GlideScopedEvaluator object.
{#GlideEvaluator-GlideScopedEvaluator__table_on3_3bx_jz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#GlideEvaluator-GlideScopedEvaluator__table_on3_3bx_jz}

### Scoped equivalent {#GlideEvaluator-GlideScopedEvaluator__section_osk_wbx_jz}

To use the GlideScopedEvaluator() method in a scoped application, use
the corresponding scoped method: [GlideScopedEvaluator()](https://servicenow-prod.fluidtopics.net/9Zcf7giOaSicZY1MT~I90A#r_ScopedGlideEvaluatorGlideScopedEvaluator "Instantiates a GlideScopedEvaluator object.").

## GlideScopedEvaluator - evaluateScript(GlideRecord grObj, String scriptField, Object
variables) {#ariaid-title3}

Evaluates a script from a GlideRecord field.
{#GlideEvaluator-evaluateScript_GR_S_O__table_l3r_hch_1r__entry__3}

| 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. Parameters]

{#GlideEvaluator-evaluateScript_GR_S_O__table_l3r_hch_1r} {#GlideEvaluator-evaluateScript_GR_S_O__table_bdf_zfr_2r__entry__2}

| Type | Description |
|-|-|
| Object | The result of the script execution. |
[Table 3. Returns]

{#GlideEvaluator-evaluateScript_GR_S_O__table_bdf_zfr_2r}  

    //For this example, we created a table: "x_app_table" with two columns: "short_description", "test_script"
    // "test_script" will store the script to be evaluated by GlideScopedEvaluator.
    var now_GR = new GlideRecord('x_app_table');
    now_GR.short_description = 'Testing GlideScopedEvaluator';
    now_GR.test_script = "gs.getUser().getName() + ' says ' + greeting; ";
    now_GR.insert();

    //setup variables to be used by the script
    var vars = {'greeting' : 'hello'};

    //Evaluate the script from the field
    var evaluator = new GlideScopedEvaluator();
    gs.info(evaluator.evaluateScript(now_GR, 'test_script', vars));

    // Now retrieve the result
    evaluator.evaluateScript(gr, 'u_test_script', null);
    gs.info(evaluator.getVariable('result'));

Output:

    admin says hello

### Scoped equivalent {#GlideEvaluator-evaluateScript_GR_S_O__section_osk_wbx_jz}

To use the evaluateScript() method in a scoped application, use the
corresponding scoped method: [evaluateScript()](https://servicenow-prod.fluidtopics.net/9Zcf7giOaSicZY1MT~I90A#r_ScopedGlideEvaluatorEvaluateScript_GlideRecord_String_Object "Evaluates a script that resides in a GlideRecord field.").

## GlideScopedEvaluator - getVariable(String name) {#ariaid-title4}

Returns a variable from a GlideScopedEvaluator object.
{#GlideEvaluator-getVariable_S__table_e3v_4dh_1r__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the variable. |
[Table 4. Parameters]

{#GlideEvaluator-getVariable_S__table_e3v_4dh_1r} {#GlideEvaluator-getVariable_S__table_mwt_wdx_jz__entry__2}

| Type | Description |
|-|-|
| Object | The value of the specified variable. |
[Table 5. Returns]

{#GlideEvaluator-getVariable_S__table_mwt_wdx_jz}  

    //setting up a record that contains the script to be executed.
    var now_GR = new GlideRecord('global'); 
    now_GR.u_short_description = 'Calculate Addition';  
    now_GR.u_test_script = "result = x + y"; 
    evaluator.evaluateScript(now_GR, "script")
    now_GR.insert(); 
     
    var evaluator = new GlideScopedEvaluator();
    evaluator.putVariable('x', 100);
    evaluator.putVariable('y', 200);
    evaluator.putVariable('result', null);
    evaluator.evaluateScript(now_GR, "script")
    now_GR.insert();

Output:

    300

### Scoped equivalent {#GlideEvaluator-getVariable_S__section_osk_wbx_jz}

To use the getVariable() method in a scoped application, use the
corresponding scoped method: [getVariable()](https://servicenow-prod.fluidtopics.net/9Zcf7giOaSicZY1MT~I90A#r_ScopedGlideEvaluatorGetVariable_String "Returns a specified variable from a GlideScopedEvaluator object.").

## GlideScopedEvaluator - putVariable(String name, Object value) {#ariaid-title5}

Puts a variable into the GlideScopedEvaluator object. These variables are available to the script that this GlideScopedEvaluator object runs.
{#GlideEvaluator-putVariable_S_O__table_e11_f2h_1r__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the variable. |
| value | Object | The value of the variable. |
[Table 6. Parameters]

{#GlideEvaluator-putVariable_S_O__table_e11_f2h_1r} {#GlideEvaluator-putVariable_S_O__table_pjt_jbx_jz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 7. Returns]

{#GlideEvaluator-putVariable_S_O__table_pjt_jbx_jz}  

    //setting up a record that contains the script to be executed.
    var now_GR = new GlideRecord('u_global_table'); 
    now_GR.u_short_description = 'Calculate Addition';  
    now_GR.u_test_script = "result = x + y";
    evaluator.evaluateScript(now_GR, "script") 
    now_GR.insert(); 
     
    var evaluator = new GlideScopedEvaluator();
    evaluator.putVariable('x', 100);
    evaluator.putVariable('y', 200);
    evaluator.putVariable('result', null);
    evaluator.evaluateScript(now_GR, "script")
    now_GR.insert();

Output:

    300

### Scoped equivalent {#GlideEvaluator-putVariable_S_O__section_osk_wbx_jz}

To use the putVariable() method in a scoped application, use the
corresponding scoped method: [putVariable()](https://servicenow-prod.fluidtopics.net/9Zcf7giOaSicZY1MT~I90A#r_ScopedGlideEvaluatorPutVariable_String_Object "Sets a variable into the GlideScopedEvaluator object. These variables are available to the script that this GlideScopedEvaluator object runs.").

