GlideRecord - Client

GlideRecord is used for database operations. Client-side GlideRecord enables the use of some GlideRecord functionality in client-side scripts, such as client scripts and UI policy scripts.

A GlideRecord contains both records and fields.

Queries made with the client-side GlideRecord are executed on the server. Therefore, a request is made from the client browser to obtain the record data.

Client-side GlideRecord is not supported in scoped applications. Instead, create a script include and use GlideAjax, or use the REST APIs.

Clientside GlideRecord - addOrderBy(String column)

Adds a column to order by in the query.

Table 1. Parameters
Name Type Description
column String The column by which to order the result set.
Table 2. Returns
Type Description
void

Clientside GlideRecord - addQuery(String query)

Adds a filter to return records using an encoded query string.

Table 3. Parameters
Name Type Description
query String An encoded query string.
Table 4. Returns
Type Description
void

Clientside GlideRecord - addQuery(String name, Object value)

Adds a filter to return records where the field is equal to the value (or is in a list of values).

Table 5. Parameters
Name Type Description
name String Name of the field to be checked.
value Object The value on which to query.
Table 6. Returns
Type Description
void

Clientside GlideRecord - addQuery(String name, Object operator, Object value)

Adds a filter to return records where the field meets the specified condition (field, operator, value).

Table 7. Parameters
Name Type Description
name String Name of the field to be checked.
operator Object An operator for the query.
value Object The value to use.
Table 8. Returns
Type Description
void

Clientside GlideRecord - deleteRecord(Function responseFunction)

Deletes the current record.

Table 9. Parameters
Name Type Description
responseFunction Function The response function for the Ajax callback.
Table 10. Returns
Type Description
Boolean True if the record was deleted. False if no record was found to delete.

Clientside GlideRecord - get(Object sys_id)

Executes a GlideRecord query for a record with the specified sys_id. This method is expected to be used to query for single records, so a next operation is performed before returning.

Table 11. Parameters
Name Type Description
sys_id Object The sys_id of the record to be found.
Table 12. Returns
Type Description
Boolean True if one or more matching records was found. False if no records were found.

Clientside GlideRecord - getEncodedQuery()

Retrieves the query condition of the current result set as an encoded query string.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
String The encoded query as a string.

Clientside GlideRecord - getLimit()

Returns the limit for records to be returned by the GlideRecord query.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
Number The limit for records to be returned by the GlideRecord query.

Clientside GlideRecord - getTableName()

Retrieves the name of the table associated with this GlideRecord.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
String The table name
var item = new GlideRecord('sc_request'); 
item.addQuery('sys_id', current.request); 
item.query(itemResponse); 
 
function itemResponse(item) {
   alert('The table is ' + item.getTableName());
}

Clientside GlideRecord - GlideRecord(String tableName)

Creates an instance of the GlideRecord class for the specified table.

Table 19. Parameters
Name Type Description
tableName String The table to be used.
var gr = new GlideRecord('incident');

Clientside GlideRecord - hasNext()

Determines if there are any more records in the GlideRecord.

Table 20. Parameters
Name Type Description
None
Table 21. Returns
Type Description
Boolean True if there are more records in the query set.

Clientside GlideRecord - insert(Function responseFunction)

Inserts a new record using the field values that have been set for the current record.

Table 22. Parameters
Name Type Description
responseFunction Function The response function.
Table 23. Returns
Type Description
String The sys_id of the inserted record, or null if the record was not inserted.
var gr = new GlideRecord('to_do');
gr.initialize(); 
gr.name = 'first to do item'; 
gr.description = 'learn about GlideRecord'; 
gr.insert();

Clientside GlideRecord - next()

Moves to the next record in the GlideRecord.

Table 24. Parameters
Name Type Description
None
Table 25. Returns
Type Description
Boolean False if there are no more records in the query set.
var rec = new GlideRecord('incident');
rec.query(recResponse);
 
function recResponse(rec) {
  while (rec.next()) { 
    alert(rec.number + ' exists');
  }
}

Clientside GlideRecord - orderBy(String column)

Specifies an orderBy column. May be called more than once to order by multiple columns.

Table 26. Parameters
Name Type Description
column String The column name to be used to order the result set.
Table 27. Returns
Type Description
void
function UpdateProjectWBS(project) {
  var count = 0;
  var child = new GlideRecord('pm_project_task');
  child.addQuery('parent', project.sys_id);
  child.orderBy('order');
  child.orderBy('number');
  child.query(childResponse);
  g_form.addInfoMessage(count + ' Project Tasks updated');
}
 
function childResponse(child) {
  var len = child.getRowCount().toString().length;
  var seq = 0;
  while (child.next()) {
    count += UpdateProjectTaskWBS(child, 1, ++seq, len, '');
  }
}

Clientside GlideRecord - query(Function responseFunction)

Runs the query against the table based on the addQuery() filter. This queries the GlideRecord table as well as any references of the table.

Table 28. Parameters
Name Type Description
responseFunction Function The response function for the Ajax callback.
Table 29. Returns
Type Description
void
var rec = new GlideRecord('incident');
rec.query(recResponse);
 
function recResponse(rec) {
  while (rec.next()) { 
   alert(rec.number + ' exists');
  } 
}

Clientside GlideRecord - setLimit(Number maxQuery)

Sets the limit for how many records are in the GlideRecord.

Table 30. Parameters
Name Type Description
maxQuery Number The limit for the number of records to retrieve.
Table 31. Returns
Type Description
void