GlideRecord - Scoped
-
- UpdatedJan 30, 2025
- 36 minutes to read
- Yokohama
- API reference
The scoped GlideRecord API is used for database operations.
The GlideRecord API is the primary means of interfacing with the database on the server-side code. A GlideRecord is an object that contains records from a single table. Use the API to instantiate a GlideRecord object and add query parameters, filters, limits, and ordering.
For information on a class that performs the same functions as GlideRecord and enforces ACLs, see Using GlideRecordSecure.
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Retrieve values from records
In most cases, don’t use dot-walking to get values from a record. Dot-walking retrieves the entire object instead of the field value. Retrieving the object uses more storage and might cause undesirable results when used in arrays or in Service Portal.
Instead of retrieving the entire object, you can use one of the following methods to copy the field values:
Scoped GlideRecord - addActiveQuery()
Adds a filter to return active records.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideQueryCondition | Filter to return active records. |
Example
Scoped GlideRecord - addEncodedQuery(String query, Boolean enforceFieldACL)
Adds an encoded query to other queries that may have been set.
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Name | Type | Description |
---|---|---|
query | String | An encoded query string. |
enforceFieldACL | Boolean | Optional. Flag that indicates whether to enforce field ACL (Access Control List) rules. Valid values:
Default: false |
Type | Description |
---|---|
void |
Example
Scoped GlideRecord - addFunction(Object function)
Applies a pre-defined GlideDBFunctionBuilder object to a record.
Use the GlideDBFunctionBuilder scoped class to define a function. After the function is defined, use the addFunction(Object function) method to apply the function to a record.
Name | Type | Description |
---|---|---|
function | Object | GlideDBFunctionBuilder object that defines a SQL operation. |
Type | Description |
---|---|
void |
Example
Output:
Scoped GlideRecord – addJoinQuery(String joinTable, String primaryField, String joinTableField)
Adds a filter to return records based on a relationship in a table related to the current GlideRecord.
You can use this method to find all the users that are in the database group via the Group Member [sys_user_grmember] table, or to find all problems that have an assigned incident via the incident.problem_id relationship.
This is not a true database join; rather, addJoinQuery() adds a subquery. So, while the result set is limited based on the join, the only fields that you have access to are those on the base table (those which are in the table with which the GlideRecord was initialized.)
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Name | Type | Description |
---|---|---|
joinTable | String | Name of table to use in the join, such as 'incident'. |
primaryField | String | Optional. Name of the field in the GlideRecord to use to join the field
specified in the joinTableField parameter. Default: sys_id |
joinTableField | String | Optional. Name of the field in the table specified in
joinTable to use to join the tables. Default: First field in the table specified in joinTable that is a reference field to the current GlideRecord table. |
Type | Description |
---|---|
GlideQueryCondition | Filter that lists records where the relationships match. |
Example
Find problems that have an incident attached. This example returns problems that have associated incidents. However, it won't pull values from the incidents that are returned as a part of the query.
Example
Find inactive problems with associated incidents.
Example
Find problems that have incidents associated where the incident caller_id field value matches that of the problem opened_by field.
Scoped GlideRecord - addNotNullQuery(String fieldName)
A filter that specifies records where the value of the field passed in the parameter is not null.
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Name | Type | Description |
---|---|---|
fieldName | String | The name of the field to be checked. |
Type | Description |
---|---|
GlideQueryCondition | A filter that specifies records where the value of the field passed in the parameter is not null. |
Example
Scoped GlideRecord - addNullQuery(String fieldName)
Adds a filter to return records where the value of the specified field is null.
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Name | Type | Description |
---|---|---|
fieldName | String | The name of the field to be checked. |
Type | Description |
---|---|
GlideQueryCondition | The query condition added to the GlideRecord. |
Example
Scoped GlideRecord - addQuery(String query)
Adds a filter to return records using an encoded query string.
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Name | Type | Description |
---|---|---|
query | String | An encoded query string . |
Type | Description |
---|---|
GlideQueryCondition | The query condition added to the GlideRecord. |
Example
Scoped GlideRecord - addQuery(String name, Object value)
Build a search query and return the rows that match the request.
If you are familiar with SQL, this method is similar to the "where" clause. One or more addQuery() calls can be made in a single query; in this case the queries are AND'ed. If any of the query statements need to be OR'ed, use the GlideQueryCondition method addOrCondition().
When addQuery() is called with only two parameters, table name and
comparison value, such as myObj.addQuery('category','Hardware');
, the
operator is assumed to be "equal to".
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Name | Type | Description |
---|---|---|
name | String | Name of the table field to query, or one of the following reserved names:
Note: For more details on the use of the reserved names, see Querying tables in script. |
value | Object | Value on which to query (not case-sensitive). |
Type | Description |
---|---|
GlideQueryCondition | Query condition added to the GlideRecord. |
Example
This code example shows how to query the active records in the incident table and then set them all to inactive.
Example
This code example adds a query for records that match "email server" in the kb_knowledge table, with search result relevancy values computed using settings from the portal text index group.
Scoped GlideRecord - addQuery(String name, String operator, Object value)
Provides the ability to build a request, which when executed, returns the rows from the specified table, that match the request.
If you are familiar with SQL, this method is similar to the "where" clause. One or more addQuery() calls can be made in a single query; in this case the queries are AND'ed. If any of the query statements need to be OR'ed, use the GlideQueryCondition method addOrCondition().
Always test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss.
You can set the glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when glide.invalid_query.returns_no_rows is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term(s) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see Available system properties.
Name | Type | Description |
---|---|---|
name | String | Table field name. |
operator | String | Query operator. The available values are dependent on the data type of the
value parameter. Numbers:
Strings (must be in upper case):
Note: Use CONTAINS instead of the LIKE operator. |
value | Object | Value on which to query (not case-sensitive). |
Type | Description |
---|---|
GlideQueryCondition | The query condition that was added to the GlideRecord. |
Example
Example
Using the IN operator.
Scoped GlideRecord - addValue(String field, Number value)
Provides atomic add and subtract operations on a specified number field at the database level for the current GlideRecord object.
Typically, a GlideRecord object is written as one record in a database. Individual field values are stored as defined. For code that adds a value to a GlideRecord field, it simply saves the field to the database with the new value, rather than atomically incrementing it.
Like setValue(), addValue() changes only take effect in the database after a subsequent call to update() or insert(). If insert() is called, the specified field is initialized with the value parameter passed into addValue().
Name | Type | Description |
---|---|---|
field | String | Name of the field in this GlideRecord to modify. Note: The associated field's data type must be an integer. This method doesn't support other data types such as longs. |
value | Integer | Amount to add to the value when the record is saved. To perform a subtraction operation, simply pass a negative value. |
Type | Description |
---|---|
void |
Example
Shows a value being added.
Output:
Example
Shows a value being subtracted.
Output:
Scoped GlideRecord - applyEncodedQuery(String queryString)
Sets the values of the specified encoded query terms and applies them to the current GlideRecord.
Name | Type | Description |
---|---|---|
queryString | String | Encoded query to apply to the current GlideRecord. |
Type | Description |
---|---|
None |
Example
Scoped GlideRecord - canCreate()
Determines if the Access Control Rules, which include the user's roles, permit inserting new records in this table.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the user's roles permit creating of records in this
table. Valid values:
|
Example
This code example writes whether the current user can create records in the Incident table in the system log.
Scoped GlideRecord - canDelete()
Determines if the Access Control Rules, which include the user's roles, permit deleting records in this table.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the user's roles permit deleting of records in this
table. Valid values:
|
Example
This code example writes whether the current user can delete records in the Incident table in the system log.
Scoped GlideRecord - canRead()
Determines if the Access Control Rules (ACLs) permit reading records in this table. This method evaluates all ACL types, such as user roles, scripted ACLs, ACLs with scripted conditions, and so on.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the user's roles permit reading of records in this
table. Valid values:
|
Example
This code example writes whether the current user can read records in the Incident table in the system log.
Scoped GlideRecord - canWrite()
Determines if the Access Control Rules, which include the user's roles, permit editing records in this table.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the user's roles permit writing of records in this
table. Valid values:
|
Example
This code example writes whether the current user can write records in the Incident table in the system log.
Scoped GlideRecord - chooseWindow(Number firstRow, Number lastRow, Boolean forceCount)
Sets a range of rows to be returned by subsequent queries.
Name | Type | Description |
---|---|---|
firstRow | Number | Zero-based index of the starting row for the range, inclusive. (A value of 0 returns the first row.) |
lastRow | Number | Zero-based index of the ending row for the range, exclusive. For example, if firstRow = 1 and lastRow = 5, four records are returned (2-5). |
forceCount | Boolean | Optional. Flag that indicates whether to force a row count query. In most
implementations of this call, the row count is performed. There are some outlying
cases, such as text searches, were a row count is not performed. Setting this flag
ensures that the row count occurs. Valid values:
Default: false |
Type | Description |
---|---|
void |
Example
This example shows how to return records 3 and 4 from the Incident [incident] table.
Output:
Scoped GlideRecord - deleteMultiple()
Deletes all records that satisfy the query.
This method does not delete attachments.
Do not use deleteMultiple() on tables with currency fields. Always delete each record individually. Also, do not use this method with the chooseWindow() or setLimit() methods when working with large tables. The setLimit() method does not limit the number of records that are deleted with deleteMultiple(). All records returned by the query are deleted regardless of setLimit().
The glide.db.forced.chunk.threshold system property sets the threshold above which forces chunk record deletions and updates. Chunking helps to prevent non-primary key deletions on huge tables from causing replication problems. For more information, see Available system properties.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
None |
Example
This example shows how to delete all inactive records from the Incident table.
Scoped GlideRecord - deleteRecord()
Deletes the current record.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the record was successfully deleted. Valid
values:
|
Example
This example shows how to delete a specified record from the Incident table.
Example
This example shows how to delete a record from the Incident table immediately after it is inserted. The incident GlideRecord must be reloaded after the insert before it can be deleted.
Output:
Scoped GlideRecord - disableSysIdInOptimization()
Disables the default optimization that prevents an extra database query from running when a user passes in a large number of sys_ids, such as grIncident.addQuery('sys_id', 'IN',
listOf200SysIds)
.
This method only effects the GlideRecord on which it’s called. To modify the sys_id limit optimization for all GlideRecords, adjust the value in the glide.db.first_pass_sys_id_list_size.max system property (default 100).
If you don't either call this method or adjust the glide.db.first_pass_sys_id_list_size.max system property and pass a list that contains more sys_id entries than defined in glide.db.first_pass_sys_id_list_size.max, the returned value from GlideRecord.getRowCount() may be incorrect.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
None |
Example
The following code example shows how to use the disableSysIdInOptimiation() method to disable the sys_id limit optimization when passing an Incident sys_id list that contains 200 entries.
Output:
Scoped GlideRecord - get(Object name, Object value)
Returns the specified record in the current GlideRecord object.
This method accepts either one or two parameters. If only a single parameter is passed in, the method assumes that it is the sys_id of the desired record. If not found, it then tries to match the value against the display value. If two parameters are passed in, the first is the name of the column within the GlideRecord to search. The second is the value to search for. If multiple records are found, use next() to access the additional records.
Name | Type | Description |
---|---|---|
name | Object | Optional. Name of the instantiated GlideRecord column to search for the specified value parameter. If only a single parameter is passed in, the method assumes that this parameter is the sys_id or display value. |
value | Object | Value to match. For calculated fields, the value is matched as is rather than running a calculation on a scripted default value for a field in the record. |
Type | Description |
---|---|
Boolean | Indicates whether the requested record was located:
|
Example
This example shows how to obtain an incident record by passing in the sys_id.
Example
This example shows how to obtain an incident record by passing the field to search (caller_id.name) and the value to match within that field.
Scoped GlideRecord - getAttribute(String fieldName)
Returns the dictionary attributes for the specified field.
Name | Type | Description |
---|---|---|
fieldName | String | Field name for which to return the dictionary attributes |
Type | Description |
---|---|
String | Dictionary attributes |
Example
Scoped GlideRecord - getClassDisplayValue()
Returns the current table's label.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Label that identifies the table. |
Example
This example prints the label of the passed in table.
Output:
Scoped GlideRecord - getDisplayValue()
Retrieves the display value for the current record.
Display values are manipulated based on the actual value in the database and user or system settings and preferences.
- Choice fields: The database value may be a number, but the display value will be more descriptive.
- Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
- Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
- Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Display value for the current record. |
Example
This example writes the display value of a specified incident record into the log.
Output:
Scoped GlideRecord - getED()
Returns the element's descriptor.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideElementDescriptor | The element's descriptor. |
Example
This example shows how to retrieve the name field for an incident GlideRecord.
Scoped GlideRecord - getElement(String fieldName)
Retrieves the GlideElement object for the specified field.
The value returned by this method is a complete GlideElement
object. The results are the equivalent of dot-walking a field value. For example,
now_GR.getElement('short_description')
provides the same result as
nowGR.short_description
.
In most cases, don’t use dot-walking to get values from a record. Dot-walking retrieves the entire object instead of the field value. Retrieving the object uses more storage and might cause undesirable results when used in arrays or in Service Portal.
Instead of retrieving the entire object, you can use one of the following methods to copy the field values:
Name | Type | Description |
---|---|---|
fieldName | String | Column name for which to return the GlideElement object. |
Type | Description |
---|---|
GlideElement | The GlideElement for the specified column of the current record. Each object describes a field in the current GlideRecord. |
Example
The following example shows how to add a new incident record with details in the Short Description field.
Output:
Scoped GlideRecord - getElements()
Returns an array of GlideElement objects. Each object describes a field in the current GlideRecord.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Array | Array of GlideElement objects. Each object describes a field in the current GlideRecord. |
Example
The following example displays the value of the name field for the five most recent records created in the Question [question] table.
Output:
Scoped GlideRecord - getEncodedQuery()
Retrieves the query condition of the current result set as an encoded query string.
For details, see Encoded query strings .
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String |
Example
Output:
Scoped GlideRecord - getLabel()
Returns the field's label.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Field's label |
Example
Scoped GlideRecord - getLastErrorMessage()
Retrieves the last error message. If there is no last error message, null is returned.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The last error message as a string. |
Example
Output:
Scoped GlideRecord - getLink(Boolean noStack)
Retrieves the link to the current record.
Name | Type | Description |
---|---|---|
noStack | Boolean | Flag indicating whether to append the sysparm_stack parameter to the returned
link. This parameter specifies the page to visit after closing the current link.
Valid values: If true, the sysparm_stack parameter is not appended to the link.
|
Type | Description |
---|---|
String | Link to the current record. |
Example
This example queries all Incident records with a priority of "1" and writes the servlet URI and the current record's link to the system log.
Output:
Scoped GlideRecord - getRecordClassName()
Retrieves the class name for the current record.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The class name. |
Example
Output:
Scoped GlideRecord - getRowCount()
Retrieves the number of rows (records) in the current GlideRecord object.
- Retrieving the number records in GlideRecord or GlideAggregate
- The GlideRecord getRowCount() and GlideAggregate getAggregate() APIs offer similar information. Use the following criteria to determine which option is best for you.
- The GlideRecord getRowCount() method tells you how many records have been returned from a query along with the records themselves. If you need the number of records in the result set before or after you iterate over the set to perform actions on the records, use this method.
- The GlideAggregate getAggregate() method retrieves only a count of records matching the query, excluding the actual records. The aggregate must be set on the GlideAggregate object prior to issuing the query.
sys_id IN
with more than 100 sys_id values, such as grIncident.addQuery('sys_id', 'IN', listOf200SysIds)
, you must
either: - Call the disableSysIdInOptimization() method on the GlideRecord.
- Or, adjust the glide.db.first_pass_sys_id_list_size.max system property to a value higher than the number of sys_ids in the list.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | Number of rows in the current GlideRecord. |
Example
The following example shows how to get the number of incidents from the Incident [incident] table.
Output:
Example
The following code example shows how to use the disableSysIdInOptimiation() method to disable the sys_id limit optimization when passing an Incident sys_id list that contains 200 entries.
Output:
Scoped GlideRecord - getTableName()
Retrieves the name of the table associated with the GlideRecord.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The table name |
Example
Scoped GlideRecord - getUniqueValue()
Gets the primary key of the record, which is usually the sys_id unless otherwise specified.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The unique primary key as a String, or null if the key is null. |
Example
Scoped GlideRecord - getValue(String name)
Retrieves the string value of an underlying element in a field.
Name | Type | Description |
---|---|---|
name | String | The name of the field to get the value from. |
Type | Description |
---|---|
String | The string value of the underlying element. Returns null if the field is empty or the field does not exist. Boolean values return as "0" and "1" string values instead of false and true. |
Example
Output:
Scoped GlideRecord - GlideRecord(String tableName)
Creates an instance of the GlideRecord class for the specified table.
Name | Type | Description |
---|---|---|
tableName | String | The table to be used. |
Example
Scoped GlideRecord - hasNext()
Determines if there are any more records in the GlideRecord object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if there are more records in the query result set. |
Example
Scoped GlideRecord - insert()
Inserts a new record using the field values that have been set for the current record.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Sys_id of the inserted record, or null if the record is not inserted. |
Example
Output:
Scoped GlideRecord - initialize()
Creates an empty record suitable for population before an insert.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
void |
Example
Scoped GlideRecord - isActionAborted()
Checks to see if the current database action is to be aborted.
isActionAborted() is initialized (set to false) for new threads and by the next() method.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates if the current database action is to be aborted. Valid
values:
|
Example
Output:
Scoped GlideRecord - isEncodedQueryValid(String query)
Verifies whether the specified encoded query is valid.
If the specified encoded query is valid, then the query is applied, just as if you had
called addEncodedQuery().
If the specified encoded query is invalid, then sys_idNotValidnull
is added
as the encoded query.
Name | Type | Description |
---|---|---|
query | String | Encoded query to validate. See Encoded query strings. |
Type | Description |
---|---|
Boolean | Flag that indicates whether the specified encoded query is valid.
|
Example
This code example shows how to validate an encoded query and then execute logic if the query is valid.
Scoped GlideRecord - isNewRecord()
Checks if the current record is a new record that has not yet been inserted into the database.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the record is new and has not been inserted into the database. |
Example
Scoped GlideRecord - isValid()
Determines if the current table is valid or if the record was successfully retrieved.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates if the table is valid or if the record was successfully
retrieved. Possible values:
|
Example
Scoped GlideRecord - isValidEncodedQuery(String query)
Verifies whether the syntax of the encoded query is correct.
""
) as the provide query:- The empty string (
""
) represents the absence of a query and returns false. - Calling
GlideRecord.addEncodedQuery("")
followed byGlideRecord.query()
returns all rows. The query method is similar to a SQL SELECT statement. In SQL, when using "SELECT * FROM foo WHERE X", the value X represents the query. If no query value is provided, all records are returned (e.g., SELECT * FROM foo).
Name | Type | Description |
---|---|---|
query | String | Encoded query to validate. See Encoded query strings. |
Type | Description |
---|---|
Boolean | Flag that indicates whether the specified encoded query is valid.
|
Example
This code example shows how to check if the encoded query is valid.
Scoped GlideRecord - isValidField(String columnName)
Determines if the specified field is defined in the current table.
Name | Type | Description |
---|---|---|
columnName | String | The name of the field. |
Type | Description |
---|---|
Boolean | True if the field is defined for the current table. |
Example
Scoped GlideRecord - isValidRecord()
Determines if a record was actually returned by the query/get record operation.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether a record was actually returned by the query/get
operation. Valid values:
|
Example
Scoped GlideRecord - isView()
Verifies whether the record was created in a view or a table.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the record was created in table that is a view.
|
Example
This code example shows how to determine if a GlideRecord was created in a view or a table.
Output:
Scoped GlideRecord - newRecord()
Creates a new GlideRecord record, sets the default values for the fields, and assigns a unique ID to the record.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
void |
Example
Output:
Scoped GlideRecord - next()
Moves to the next record in the GlideRecord object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates if there is a "next" record in the GlideRecord. Valid
values:
|
Example
Scoped GlideRecord - _next()
Moves to the next record in the GlideRecord. Provides the same functionality as next(), use this method if the GlideRecord has a column named next.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether there are more records in the query set. Possible
values:
|
Example
The following example shows how to list each record in the Incidents [incident] table.
Output:
Scoped GlideRecord - operation()
Determines if an operation is insert, update, or delete.
Knowing the operation enables using current.operation() to make a generic business rule which can handle each operation uniquely.
For information on using the global variable current, refer to Global variables in business rules.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The current operation. Possible values:
|
Example
The following example shows how to use this method in a business rule. The operation() method detects which operation triggered an event and performs a different action depending for update and insert operations.
Scoped GlideRecord - orderBy(String name)
Specifies an orderBy column.
Call this method more than once to order by multiple columns. Results are arranged in ascending order. To arrange records in descending order, see Scoped GlideRecord - orderByDesc(String name).
Name | Type | Description |
---|---|---|
name | String | Column name to use to order the records in this GlideRecord object. |
Type | Description |
---|---|
void |
Example
The following example shows how to order incident records in ascending order by Short Description.
Output:
Scoped GlideRecord - orderByDesc(String name)
Specifies a descending orderBy column.
Call this method more than once to order by multiple columns. Results are arranged in descending order. To arrange records in ascending order, see Scoped GlideRecord - orderBy(String name).
Name | Type | Description |
---|---|---|
name | String | Column name to use to order the records in a GlideRecord object. |
Type | Description |
---|---|
void |
Example
The following example shows how to order incident records in descending order by Short Description.
Output:
Scoped GlideRecord - query(String field, String value)
Runs a query against the table based on the filters specified in the query methods such as addQuery() and addEncodedQuery().
This method queries the GlideRecord table as well as any references of the table. For more information, see Querying tables in script.
Name | Type | Description |
---|---|---|
name | String | Optional - must also specify a value parameter. Name of the field to search for the value specified in the value parameter. Note: This method is typically run without arguments, but you can specify a name-value pair to filter records containing the specified values. If the parameters are specified, the "name=value" condition is added
to the query.
|
value | String | Optional - must also specify a field parameter. Value to search for in the specified field parameter. |
Type | Description |
---|---|
void |
Example
The following example shows how to scan the System Dictionary [sys_dictionary] for tables with a query field.
Output:
Scoped GlideRecord - _query(String field, String value)
Runs a query against the table based on the filters specified in the query methods such as addQuery() and addEncodedQuery(). This method is intended to be used on tables in which there's a column named "query", which might cause errors running the query() method.
This method queries the GlideRecord table as well as any references of the table. For more information, see Querying tables in script.
Name | Type | Description |
---|---|---|
name | String | Optional - must also specify a value parameter. Name of the field to search for the value specified in the value parameter. Note: This method is typically run without arguments, but you can specify a name-value pair to filter records containing the specified values. If the parameters are specified, the "name=value" condition is added
to the query.
|
value | String | Optional - must also specify a field parameter. Value to search for in the specified field parameter. |
Type | Description |
---|---|
void |
Example
The following example shows how query the Knowledge Feedback [kb_feedback] table and list KB articles with comments that include Excel.
Output:
Scoped GlideRecord - setAbortAction(Boolean b)
Sets a flag to indicate if the next database action (insert, update, delete) is to be aborted. This is often used in business rules.
Use in an onBefore
business rule to prevent the database action from being done. The business rule continues to run after
setAbortAction() is called. Calling setAbortAction() does not stop subsequent business rules from executing. Calling this method only prevents the database action from occurring.
Name | Type | Description |
---|---|---|
b | Boolean | True to abort the next action. False if the action is to be allowed. |
Type | Description |
---|---|
void |
Example
Scoped GlideRecord - setLimit(Number maxNumRecords)
Sets the limit for number of records are fetched by the GlideRecord query.
Name | Type | Description |
---|---|---|
maxNumRecords | Number | The maximum number of records to fetch. |
Type | Description |
---|---|
void |
Example
Scoped GlideRecord - setNewGuidValue(String guid)
Sets the sys_id value for the current record.
Name | Type | Description |
---|---|---|
guid | String | GUID to assign to the current record. |
Type | Description |
---|---|
void |
Example
Scoped GlideRecord - setValue(String name, Object value)
Sets the value of the field with the specified name to the specified value.
Normally the script does a now_GR.category = value
. However, if the
element name is itself a variable then you can use now_GR.setValue(elementName,
value)
. When setting a value, ensure the data type of the field matches the data
type of the value you enter.
- Not for authentication with password2 fields
- The setValue() method passes password2 data as clear text, which results in an error about expecting encrypted data. Additionally, using the setValue() method for password2 fields exposes data that
should be encrypted.
For password2 authentication, use the setDisplayValue() method instead.
Name | Type | Description |
---|---|---|
name | String | Name of the field. |
value | Object | Value to assign to the field. |
Type | Description |
---|---|
None |
Example
Scoped GlideRecord - setWorkflow(Boolean enable)
Enables or disables the running of business rules, script engines, and audit.
Name | Type | Description |
---|---|---|
enable | Boolean | Flag that indicates whether to enable or disable the running of business rules, script engines, and audit. Valid values:
Default: true |
Type | Description |
---|---|
void |
Example
Scoped GlideRecord - update(String reason)
Updates the GlideRecord with any changes that have been made. If the record does not already exist, it is inserted.
Name | Type | Description |
---|---|---|
reason | String | Optional. Reason for the update. The reason appears in the audit record. |
Type | Description |
---|---|
String | Sys_id of the new or updated record. Returns null if the update fails. |
Example
The following example shows how to update the Short Description field of an incident.
Output:
Scoped GlideRecord - updateMultiple()
Updates each GlideRecord in a stated query with a specified set of changes.
This method does not support adding multiple journal entries.
The glide.db.forced.chunk.threshold system property sets the threshold above which forces chunk record deletions and updates. Chunking helps to prevent non-primary key deletions on huge tables from causing replication problems. For more information, see Available system properties.
gr_Now.setValue('<field_name>', '4'));
instead of gr_Now.<field_name> =
4
.This method sets new values and does not clear existing values. To clear an existing value, use the setValue() method and set the field to 'NULL'. For more information, see Setting a GlideRecord variable to 'NULL'.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
None |
Example
This example shows how to update the state of all active incidents to 4 - "Awaiting User Info".
Scoped GlideRecord - updateWithReferences(Object reason)
Updates a record and also inserts or updates any related records with the information provided.
Name | Type | Description |
---|---|---|
reason | Object | Reason for the updates. The reason is displayed in the audit record. |
Type | Description |
---|---|
String | The sys_id for the record being updated. |
Example
If processing an incident where the Caller ID is set to reference sys_user record 'John Doe,' then the following code would update John Doe's user record. If processing an incident where there's no caller ID specified, then the following code creates a new sys_user record with the provided information (first_name, last_name) and sets the caller ID value to the newly created sys_user record.
On this page
- Retrieve values from records
- Scoped GlideRecord - addActiveQuery()
- Scoped GlideRecord - addEncodedQuery(String query, Boolean enforceFieldACL)
- Scoped GlideRecord - addFunction(Object function)
- Scoped GlideRecord – addJoinQuery(String joinTable, String primaryField, String
joinTableField)
- Scoped GlideRecord - addNotNullQuery(String fieldName)
- Scoped GlideRecord - addNullQuery(String fieldName)
- Scoped GlideRecord - addQuery(String query)
- Scoped GlideRecord - addQuery(String name, Object value)
- Scoped GlideRecord - addQuery(String name, String operator, Object value)
- Scoped GlideRecord - addValue(String field, Number value)
- Scoped GlideRecord - applyEncodedQuery(String queryString)
- Scoped GlideRecord - canCreate()
- Scoped GlideRecord - canDelete()
- Scoped GlideRecord - canRead()
- Scoped GlideRecord - canWrite()
- Scoped GlideRecord - chooseWindow(Number firstRow, Number lastRow, Boolean forceCount)
- Scoped GlideRecord - deleteMultiple()
- Scoped GlideRecord - deleteRecord()
- Scoped GlideRecord - disableSysIdInOptimization()
- Scoped GlideRecord - get(Object name, Object value)
- Scoped GlideRecord - getAttribute(String fieldName)
- Scoped GlideRecord - getClassDisplayValue()
- Scoped GlideRecord - getDisplayValue()
- Scoped GlideRecord - getED()
- Scoped GlideRecord - getElement(String fieldName)
- Scoped GlideRecord - getElements()
- Scoped GlideRecord - getEncodedQuery()
- Scoped GlideRecord - getLabel()
- Scoped GlideRecord - getLastErrorMessage()
- Scoped GlideRecord - getLink(Boolean noStack)
- Scoped GlideRecord - getRecordClassName()
- Scoped GlideRecord - getRowCount()
- Scoped GlideRecord - getTableName()
- Scoped GlideRecord - getUniqueValue()
- Scoped GlideRecord - getValue(String name)
- Scoped GlideRecord - GlideRecord(String tableName)
- Scoped GlideRecord - hasNext()
- Scoped GlideRecord - insert()
- Scoped GlideRecord - initialize()
- Scoped GlideRecord - isActionAborted()
- Scoped GlideRecord - isEncodedQueryValid(String query)
- Scoped GlideRecord - isNewRecord()
- Scoped GlideRecord - isValid()
- Scoped GlideRecord - isValidEncodedQuery(String query)
- Scoped GlideRecord - isValidField(String columnName)
- Scoped GlideRecord - isValidRecord()
- Scoped GlideRecord - isView()
- Scoped GlideRecord - newRecord()
- Scoped GlideRecord - next()
- Scoped GlideRecord - _next()
- Scoped GlideRecord - operation()
- Scoped GlideRecord - orderBy(String name)
- Scoped GlideRecord - orderByDesc(String name)
- Scoped GlideRecord - query(String field, String value)
- Scoped GlideRecord - _query(String field, String value)
- Scoped GlideRecord - setAbortAction(Boolean b)
- Scoped GlideRecord - setLimit(Number maxNumRecords)
- Scoped GlideRecord - setNewGuidValue(String guid)
- Scoped GlideRecord - setValue(String name, Object value)
- Scoped GlideRecord - setWorkflow(Boolean enable)
- Scoped GlideRecord - update(String reason)
- Scoped GlideRecord - updateMultiple()
- Scoped GlideRecord - updateWithReferences(Object reason)