Scriptable service catalog variables
-
- UpdatedAug 1, 2024
- 4 minutes to read
- Xanadu
- Building applications
You can use scripting to reference any request item variable from a table in scoped and non-scoped environment.
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
Set a variable
Create an inventory item with fields set from variables
Get GlideElementVariable of variables and variable sets associated with a GlideRecord
Get the name value pair of variables associated with a GlideRecord
Get a list of GlideElementVariable for variables within a task record
Get a list of GlideElementVariable for variables (including multi-row variable set) within a task record
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).
Example to access variables of GlideRecord for the Task table
Example to access a multi-row variable set of GlideRecord for the Task table
Multi-row variable set
Operation | Usage |
---|---|
Table operations | |
Return JSON array value as String | |
Set value of a multi-row variable set | 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 | Note: An array of ordered (key, value) pairs is also applicable as input. |
Row operations | |
Get the current row count | |
Returns the row specified by the variable "i" - 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> | |
Add an empty row at the end of the table and return a scriptable object | |
Delete a row |
Notes and limitations
- //Single column of table_Var
- now_GR.variables.table_var.var1
- now_GR.variables.table_var.var1 = <val>
- You can only set a variable in a before business rule. Variables set in an after rule are not 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.
On this page
- Print a variable
- Set a variable
- Create an inventory item with fields set from variables
- Get GlideElementVariable of variables and variable sets associated with a
GlideRecord
- Get the name value pair of variables associated with a GlideRecord
- Get a list of GlideElementVariable for variables within a task record
- Get a list of GlideElementVariable for variables (including multi-row variable set) within
a task record
- APIs for GlideElementVariable
- Example to access variables of GlideRecord for the Task table
- Example to access a multi-row variable set of GlideRecord for the Task table
- Multi-row variable set
- Notes and limitations