---
sourceDocument: Brazil ServiceNow AI Platform Capabilities
sourceDocumentLink: https://www.servicenow.com/docs/r/servicenow-platform

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil ServiceNow AI Platform Capabilities

ft:clusterId :

    - platcap

bundleId :

    - platcap

workflow :

    - Platform


---

# Referencing Service Catalog variables

# Referencing Service Catalog variables in server-side scripts {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Referencing Service Catalog variables in server-side scripts

This guide explains how ServiceNow customers can reference and manipulate Service Catalog variables within server-side scripts effectively.
It covers scripting approaches in both scoped and non-scoped environments, focusing on accessing variables from request items, variable sets, and multi-row variable sets.
This capability is essential for automating processes, integrating catalog data, and customizing workflows based on user inputs in Service Catalog requests.
Show full answer Show less  

## Key Features

* **Referencing Variables:** Use `current.variables.<variablename>` to access variables on the current record. Variables within variable sets can be accessed via `current.variables.<variablesetname>.<variablename>`.
* **Variable Sets and Roles:** Variable sets have independent roles that override individual variable roles, controlling read, write, and create permissions for variables inside the set.
* **Business Rule Constraints:** Variables can only be set in before business rules because after business rules do not write variable changes back to the database.
* **Time Zone Handling:** Date/time variables follow system-wide GMT storage and user-local time zone display conventions.
* **GlideRecord Access:** Use GlideRecord queries on task tables (e.g., `screqitem`) to retrieve variable objects and manipulate their values programmatically.
* **GlideElementVariable APIs:** Methods such as `isMultiRow()`, `getQuestion()`, `canRead()`, and `getDecryptedValue()` provide detailed control and access over variables and multi-row variable sets.
* **Multi-row Variable Sets:** Support for complex variable sets with multiple rows, enabling operations like adding, deleting rows, and accessing or setting individual cell values. These are accessible through methods like `getRows()`, `getRowCount()`, and `addRow()`.

## Practical Usage Examples

* **Printing a variable:** Retrieve and log a variable's value using `gs.print(current.variables.variablename)`.
* **Setting a variable:** Assign values to variables programmatically within before business rules, e.g., `current.variables.name = "Auto-Generated:" + current.variables.assettag;`.
* **Creating CMDB records:** Use variables' values to populate and insert configuration items such as computers in the CMDB.
* **Iterating variables:** Loop through variables or multi-row variable sets on a request item to read labels and values for processing or logging.
* **Manipulating multi-row variable set data:** Access and modify rows and cells individually, add new rows, or delete existing rows, enabling dynamic catalog item configurations.

## Key Outcomes

By following these scripting techniques, ServiceNow customers can:

* Efficiently access and manipulate Service Catalog variables and variable sets in server-side scripts.
* Implement dynamic and automated workflows based on user inputs in catalog requests.
* Manage permissions and data integrity through variable set role controls.
* Handle complex data structures like multi-row variable sets for advanced catalog item configurations.
* Ensure data consistency with proper timing of script execution (before business rules) and time zone handling for date/time variables.  
You can use scripting to reference any request item variable from a table in scoped and
non-scoped environment.  
An example of a variable reference follows.

    current.variables.<variable_name>

Where current refers to the current record, and <var class="keyword varname">&lt;variable_name&gt;</var> is the name of your variable.  
Note:  
To reference a variable from JavaScript, it must have a name.

When a variable is part of a variable set, you can reference it as
`current.variables.<variable_name>` or
`current.variables.<variable_set_name>.<variable_name>`.

Variable set is also a first-class citizen in Service Catalog. Like variables, a variable set has read, write, and create roles. If roles are provided for a variable set, the roles are applicable for the variables within the set. Roles of an individual
variable are overridden by the roles of the variable set.  
Note:  
* You can only set a variable in a before business rule. Variables set in an after rule aren't written to the database.
* There is nothing in place to prevent namespace collision with variables. Creating two variables named computer_speed would result in only one of them showing up; the second one would overwrite the first one.
* Date/time variables use the same time zone formatting and storage rules as all other dates in the system. They are stored internally in GMT, but translated into the user's local time zone and format for display.
{#c_ScriptableServiceCatalogVariables__ol_am5_zq4_pp}  

## Print a variable {#c_ScriptableServiceCatalogVariables__example-print-variable}

    var original = current.variables.original_number;
    gs.print(original);

## Set a variable {#c_ScriptableServiceCatalogVariables__example-set-variable}

    current.variables.name = "Auto-Generated:" + current.variables.asset_tag;

## Create an inventory item with fields set from variables {#c_ScriptableServiceCatalogVariables__example-create-inventory-item}

    doCreation(); 

    function doCreation ( ) { 
    var create = current.variables.create_item; 
    if (create == 'true') { // we want to create an asset
      var computer = new GlideRecord('cmdb_ci_computer');
      computer.initialize();
      computer.asset_tag = current.variables.asset_tag;
      computer.serial_number = current.variables.serial_number;
      computer.name = current.variables.name;
      computer.manufacturer = current.variables.company;
      computer.insert(); } }

## Get GlideElementVariable of variables and variable sets associated with a GlideRecord {#c_ScriptableServiceCatalogVariables__example-get-glide-element-variable}

    now_GR.variables

## Get the name value pair of variables associated with a GlideRecord {#c_ScriptableServiceCatalogVariables__example-get-name-value-pair}

    now_GR.variables.getVariableValue();

## Get a list of GlideElementVariable for variables within a task record {#c_ScriptableServiceCatalogVariables__example-get-elements-list}

    now_GR.variables.getElements();

## Get a list of GlideElementVariable for variables (including multi-row variable set) within
a task record {#c_ScriptableServiceCatalogVariables__example-get-elements-list-multi-row}

    now_GR.variables.getElements(true);

Note:  
The getElements() method returns all the variables present on the given task record except for the formatter variables like label, break, container end, container split, and so on.  
APIs for GlideElementVariable:

* now_GR.variables.\<var_name\>.isMultiRow(): Get whether the GlideElementVariable is a multi-row variable set or a variable.
* now_GR.variables.\<var_name\>.getQuestion(): Get the Question object for a variable. Applicable only for a variable (isMultiRow() is false) and not for a multi-row variable set.
* now_GR.variables.\<var_name\>.getLabel(): Get the label of the GlideElementVariable. For a variable, the label of the variable is returned. For multi-row variable set, the title of the variable set is returned.
* now_GR.variables.\<var_name\>.canRead(): Get whether the user can view a variable or multi-row variable set.
* now_GR.variables.\<var_name\>.canWrite(): Get whether the user can edit a variable or multi-row variable set.
* now_GR.variables.\<var_name\>.getDecryptedValue(): Get the decrypted value for a masked variable. Applicable only for a masked variable.
* now_GR.variables.\<var_name\>.getRows(): Get the list of row objects for a multi-row variable set. Applicable only for a multi-row variable set (isMultiRow() is true).
* now_GR.variables.\<var_name\>.getRowCount(): Get the number of rows for multi-row variable set. Applicable only for a multi-row variable set (isMultiRow() is true).
{#c_ScriptableServiceCatalogVariables__ul_mw5_tn1_j3b}  

## Access variables of GlideRecord for the Task table {#c_ScriptableServiceCatalogVariables__example-access-variables-task-table}

    var now_GR = new GlideRecord('sc_req_item'); 
    if (now_GR.get('635a1f5387320300e0ef0cf888cb0b73')) { 
        var variables = now_GR.variables.getElements(); 
        for (var i=0;i<variables.length;i++) { 
            var question = variables[i].getQuestion(); 
            gs.log(question.getLabel() + ":" + question.getValue()) 
        } 
    }

## Access a multi-row variable set of GlideRecord for the Task table {#c_ScriptableServiceCatalogVariables__example-access-multi-row-variable-set}

    var now_GR = new GlideRecord('sc_req_item');
    now_GR.get('02c38dcd87013300e0ef0cf888cb0bb2');

    var vars = now_GR.variables.getElements(true);

    for (var i=0; i<vars.length; i++) {
        var now_V = vars[i];
        if (now_V.isMultiRow()) {
            var rows = now_V.getRows();
            for (var j=0; j<now_V.getRowCount(); j++) {
                var row = rows[j];
                var cells = row.getCells();
                for (var k=0; k<cells.length; k++) {
                    var cell = cells[k];
                    gs.info(cell.getLabel() + ":" + cell.getCellDisplayValue())
                }
            }
        }
    }

## Multi-row variable set {#c_ScriptableServiceCatalogVariables__example_hrs_sfg_mjc}

{#c_ScriptableServiceCatalogVariables__table_xz2_tnk_b2b__entry__2}

| Operation | Usage |
|-|-|
| Table operations ||
| Return JSON array value as String | now_GR.variables.table_var |
| Set value of a multi-row variable set | now_GR.variables.table_var = <val> Note: An array of ordered (key, value) pairs is also applicable as input. |
| Get value of column, var1, of a multi-row variable set | now_GR.variables.table_var.var1 |
| Set value of a variable set, var1 | now_GR.variables.table_var.var1 = <val> Note: An array of ordered (key, value) pairs is also applicable as input. |
| Row operations ||
| Get the current row count | now_GR.variables.table_var.getRowCount() |
| Returns the row specified by the variable "index" - getRow(\<int\> index) | var row = now_GR.variables.table_var.getRow(<int> index); |
| Get the cell value for a question column mapped to \<var_name\> | row.<var_name> |
| Set the cell value for a question column mapped to \<var_name\> | row.setCellValue('<var_name>',value) |
| Set the cell value for a question column mapped to \<var_name\> | row.<var_name> = value |
| Add an empty row at the end of the table and return a scriptable object | var row = now_GR.variables.table_var.addRow() |
| Delete a row | row.deleteRow() |
[Table 1. Examples of multi-row variable set operations]

{#c_ScriptableServiceCatalogVariables__table_xz2_tnk_b2b}

