Thank you for your feedback.
Form temporarily unavailable. Please try again or contact to submit your comments.

Scriptable service catalog variables

Log in to subscribe to topics and get notified when content changes.

Scriptable service catalog variables

You can use scripting to reference any variables used by a request item from any table.

An example of a variable reference follows.
Where current refers to the current record, and <variable_name> is the name of your variable.
Note: In order 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.

Print a variable

var original = current.variables.original_number;

Set a variable = "Auto-Generated:" + current.variables.asset_tag;

Create an inventory item with fields set from variables


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.asset_tag = current.variables.asset_tag;
  computer.serial_number = current.variables.serial_number; =;
  computer.manufacturer =;
  computer.insert(); } }

Get GlideElementVariable of variables and variable sets associated with a GlideRecord


Get the name value pair of variables associated with a GlideRecord


Get GlideElementVariable for variables within a GlideRecord


Return the Question object of each GlideElementVariable


Example to access variables of GlideRecord for the Task table

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

Multi-row variable set

Table 1. Multi-row variable set
Operation Usage
Table operations
Return JSON array value as String
Set value of a multi-row variable set
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
Set value of a variable set, var1
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
Return the ith row
var row = gr.variables.table_var.getRow(<int> i);
Get the cell value for a question column mapped to <var_name>
Set the cell value for a question column mapped to <var_name>
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 = gr.variables.table_var.addRow()
Delete a row

Notes and limitations

//Single column of table_Var


gr.variables.table_var.var1 = <val>

  1. You can only set a variable in a before business rule. Variables set in an after rule are not written to the database.
  2. 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.
  3. 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.