<h2>GlideRecord - setLimit(Number limit)</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="concept" /><meta name="DC.title" content="GlideRecord" /><meta name="abstract" content="The GlideRecord API is used for database operations." /><meta name="description" content="The GlideRecord API is used for database operations." /><meta name="DC.subject" content="GlideRecord, addActiveQuery(), addDomainQuery(Object glideRecord), addEncodedQuery(String query), GlideRecord, addFunction(Object function), addInactiveQuery(), addJoinQuery(String table), addJoinQuery(String table, String primaryField), addJoinQuery(String table, String primaryField, String joinTableField), addNotNullQuery(String fieldName), addNullQuery(String fieldName), addQuery(String name, Object operator, Object value), , applyTemplate(String template), autoSysFields(Boolean e), canCreate(), canDelete(), canRead(), canWrite(), changes(), deleteMultiple(), deleteRecord(), find(String columnName, String value), get(Object name, Object value), getAttribute(String fieldName), getClassDisplayValue(), getDisplayValue(), getED(), getElement(String fieldName), getEncodedQuery(), getEscapedDisplayValue(), getFields(), getLabel(), getLink(Boolean noStack), getLocation(), getPlural(), getRelatedLists(), getRelatedTables(), getRowCount(), getRowNumber(), getTableName(), Global GlideRecord, getUniqueValue(), getValue(String fieldName), GlideRecord(String tableName), hasAttachments(), hasNext(), initialize(), insert(), insertWithReferences(), instanceOf(String className), isValid(), isValidField(String fieldName), isValidRecord(), newRecord(), next(), _next(), operation(), orderBy(String fieldName), orderByDesc(String, fieldName), query(String field, String value), _query(String field, String value), restoreLocation(), saveLocation(), setAbortAction(Boolean b), setDisplayValue(String name, Object value), setForceUpdate(Boolean force), setLimit(Number limit), setLocation(Number rowNumber), setNewGuid(), setNewGuidValue (String guid), setQueryReferences(Boolean queryReferences), setUseEngines(Boolean e), GlideRecord, setValue(), setWorkflow(Boolean e), update(Object reason), GlideRecord, updateMultiple(), updateWithReferences(Object reason)" /><meta name="keywords" content="GlideRecord, addActiveQuery(), addDomainQuery(Object glideRecord), addEncodedQuery(String query), GlideRecord, addFunction(Object function), addInactiveQuery(), addJoinQuery(String table), addJoinQuery(String table, String primaryField), addJoinQuery(String table, String primaryField, String joinTableField), addNotNullQuery(String fieldName), addNullQuery(String fieldName), addQuery(String name, Object operator, Object value), , applyTemplate(String template), autoSysFields(Boolean e), canCreate(), canDelete(), canRead(), canWrite(), changes(), deleteMultiple(), deleteRecord(), find(String columnName, String value), get(Object name, Object value), getAttribute(String fieldName), getClassDisplayValue(), getDisplayValue(), getED(), getElement(String fieldName), getEncodedQuery(), getEscapedDisplayValue(), getFields(), getLabel(), getLink(Boolean noStack), getLocation(), getPlural(), getRelatedLists(), getRelatedTables(), getRowCount(), getRowNumber(), getTableName(), Global GlideRecord, getUniqueValue(), getValue(String fieldName), GlideRecord(String tableName), hasAttachments(), hasNext(), initialize(), insert(), insertWithReferences(), instanceOf(String className), isValid(), isValidField(String fieldName), isValidRecord(), newRecord(), next(), _next(), operation(), orderBy(String fieldName), orderByDesc(String, fieldName), query(String field, String value), _query(String field, String value), restoreLocation(), saveLocation(), setAbortAction(Boolean b), setDisplayValue(String name, Object value), setForceUpdate(Boolean force), setLimit(Number limit), setLocation(Number rowNumber), setNewGuid(), setNewGuidValue (String guid), setQueryReferences(Boolean queryReferences), setUseEngines(Boolean e), GlideRecord, setValue(), setWorkflow(Boolean e), update(Object reason), GlideRecord, updateMultiple(), updateWithReferences(Object reason)" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-server.html" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-implementation-reference.html" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-reference.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2024-02-01" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="c_GlideRecordAPI" /><link rel="stylesheet" type="text/css" href="../../../../../CSS/commonltr.css" /><title>GlideRecord</title></head><body class="api-class"> <div class="nested0" id="c_GlideRecordAPI"> <h1 class="title topictitle1" id="ariaid-title1">GlideRecord </h1> <div class="body conbody"><p class="shortdesc">The <span class="keyword apiname">GlideRecord</span> API is used for database operations.</p> <div class="section" id="c_GlideRecordAPI__section_rcn_z51_wnb"> <p class="p">The <span class="keyword apiname">GlideRecord</span> 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.</p> <p class="p"><span class="ph">See the <a class="xref" href="https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_scripting_in_servicenow/app_store_learnv2_scripting_utah_server_side_scripting/app_store_learnv2_scripting_utah_gliderecord" target="_blank" rel="noopener noreferrer">GlideRecord</a> article for details on building and running queries.</span></p> <p class="p">For information about <span class="keyword apiname">GlideRecordSecure</span>, which is a class inherited from <span class="keyword apiname">GlideRecord</span> that performs the same functions as <span class="keyword apiname">GlideRecord</span>, and also enforces ACLs, see the <a class="xref" href="../script/glide-server-apis/topic/p_GlideServerAPIs.dita/p_GlideServerAPIs.html" target="_blank" rel="noopener noreferrer">GlideServer APIs</a>.</p> <p class="p">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 <span class="keyword apiname">insert()</span>, <span class="keyword apiname">update()</span>, <span class="keyword apiname">deleteRecord()</span>, or <span class="keyword apiname">deleteMultiple()</span> method on bad query results can result in data loss.</p> <p class="p">You can set the <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> </div> <div class="section" id="c_GlideRecordAPI__section_t45_vmd_npb"><h2 class="title sectiontitle">Retrieve values from records</h2> <p class="p">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 <span class="ph">Service Portal</span>.</p> <p class="p">Instead of retrieving the entire object, you can use one of the following methods to copy the field values:</p> <ul class="ul" id="c_GlideRecordAPI__gr-api-dot-walk-global-rec-lnx"><li class="li"><a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-getValue_String" title="Retrieves the string value of a specified field.">getValue()</a></li><li class="li"><a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-getDisplayValue" title="Retrieves the display value for the current record.">getDisplayValue()</a></li></ul> <div class="p">If dot-walking through a GlideElement object is necessary, use the <span class="keyword apiname">toString()</span> method to retrieve values. For example, you might need the current caller's manager sys_id to set another reference field. The following example shows how to get the string value instead of the entire object:<pre class="pre codeblock"><code>var mgr = current.caller_id.manager.toString();</code></pre></div> </div> <div class="section" id="c_GlideRecordAPI__section_vwz_mkd_npb"> <div class="p">See also:<ul class="ul" id="c_GlideRecordAPI__ul_mky_nkd_npb"><li class="li"><a class="xref" href="../../GlideAggregate/concept/c_GlideAggregateAPI.html" title="GlideAggregate enables creating database aggregation queries.">GlideAggregate</a></li><li class="li"><a class="xref" href="../../GlideElement_global/concept/c_GlideElementAPI.html" title="The GlideElement API provides a number of convenient script methods for dealing with fields and their values. GlideElement methods are available for the fields of the current GlideRecord.">GlideElement</a></li><li class="li"><a class="xref" href="../../GlideQuery/concept/GlideQueryGlobalAPI.html" title="The GlideQuery API is an alternative to GlideRecord to perform CRUD operations on record data from server-side scripts.">GlideQuery</a></li></ul> </div> </div> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../../../build/applications/concept/api-server.html" title="Use server APIs in scripts to change the functionality of applications, or when you create new applications.">Server API reference</a></div> </div> </div><div class="topic reference nested1 api-method" id="r_GlideRecord-AddActiveQuery"> <h2 class="title topictitle2" id="ariaid-title2">GlideRecord - addActiveQuery()</h2> <div class="body refbody"><p class="shortdesc">Adds a filter to return active records.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddActiveQuery__table_bk4_zkp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 1. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e297">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e300">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e303">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e297 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e300 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e303 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddActiveQuery__table_ck4_zkp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 2. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e338">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e341">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e338 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e341 ">Filter to return active records.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var inc = new GlideRecord('incident'); inc.addActiveQuery(); inc.query();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddActiveQuery__section_t1r_lbs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addActiveQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#SGR-addActiveQuery" title="Adds a filter to return active records.">addActiveQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddDomainQuery_Object"> <h2 class="title topictitle2" id="ariaid-title3">GlideRecord - addDomainQuery(Object glideRecord)</h2> <div class="body refbody"><p class="shortdesc">Changes the domain used for the query from the user's domain to the domain of the provided GlideRecord.</p> <div class="section"> <p class="p">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 <span class="keyword apiname">insert()</span>, <span class="keyword apiname">update()</span>, <span class="keyword apiname">deleteRecord()</span>, or <span class="keyword apiname">deleteMultiple()</span> method on bad query results can result in data loss.</p> <p class="p">You can set the <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> <p class="p">This function requires the Domain Support - Domain Extensions Installer (com.glide.domain.msp_extensions.installer) plugin.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddDomainQuery_Object__table_ukh_fmp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 3. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e477">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e480">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e483">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e477 ">glideRecord</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e480 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e483 ">GlideRecord from which to obtain the domain.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddDomainQuery_Object__table_vkh_fmp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 4. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e520">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e523">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e520 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e523 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>//This example requires the Domain plugin be active, the Group table is the specified //Domain table, and the ITIL user is in the Database Atlanta domain //From any domain (using queryNoDomain()) look up the incidents that an ITIL user can only see //who is in the Database Atlanta domain, should expect all incidents with the global or the //Database Atlanta domain specified. var domain = new GlideRecord('sys_user'); domain.addQuery('user_name', 'itil'); domain.queryNoDomain(); if (domain.next()) { var domainQuery = new GlideRecord('incident'); domainQuery.addQuery('active', true); domainQuery.addDomainQuery(domain); domainQuery.query(); gs.print('Number of Incidents for ITIL user: ' + domainQuery.getRowCount()); while (domainQuery.next()) gs.print(domainQuery.number); }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddDomainQuery_Object__section_bct_nbs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">This method is not available in scoped applications.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddEncodedQuery_String"> <h2 class="title topictitle2" id="ariaid-title4">GlideRecord - addEncodedQuery(String query)</h2> <div class="body refbody"><p class="shortdesc">Adds an encoded query to other queries that may have been set.</p> <div class="section"> <p class="p">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 <span class="keyword apiname">insert()</span>, <span class="keyword apiname">update()</span>, <span class="keyword apiname">deleteRecord()</span>, or <span class="keyword apiname">deleteMultiple()</span> method on bad query results can result in data loss.</p> <p class="p">You can set the <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddEncodedQuery_String__table_j3p_mlp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 5. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e646">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e649">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e652">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e646 ">query</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e649 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e652 ">An <a class="xref" href="../use/using-lists/concept/c_EncodedQueryStrings.dita/c_EncodedQueryStrings.html" target="_blank" rel="noopener noreferrer">encoded query string</a>.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddEncodedQuery_String__table_k3p_mlp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 6. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e693">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e696">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e693 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e696 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var queryString = "priority=1^ORpriority=2"; var now_GR = new GlideRecord('incident'); now_GR.addEncodedQuery(queryString); now_GR.query(); while (now_GR.next()) { gs.addInfoMessage(now_GR.number); }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddEncodedQuery_String__section_un1_qbs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addEncodedQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddEncodedQuery_String" title="Adds an encoded query to other queries that may have been set.">addEncodedQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="GlideRecord-addExtraField_S"> <h2 class="title topictitle2" id="ariaid-title5">GlideRecord - addExtraField(String dotWalkedField)</h2> <div class="body refbody"><p class="shortdesc">Queries one or more dot-walked fields from a form or script in a single request.</p> <div class="section"> <p class="p">The <span class="keyword apiname">addExtraField()</span> method allows you to query dot-walked fields in a single database request, rather than perform multiple queries per dot-walked element in a form or script (which requires multiple round trips to the database).</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-addExtraField_S__table_ctk_qcx_hzb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 7. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e794">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e797">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e800">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e794 ">dotWalkedField</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e797 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e800 ">The dot-walked field name. Levels of field names are separated by dots (periods). For example, enter the value <code class="ph codeph">Caller.Company</code> if you want to query the <span class="ph menucascade"><span class="ph uicontrol">Company</span> > <span class="ph uicontrol">Caller</span></span> condition in the Incident [incident] table.<p class="p">The format of <span class="keyword parmname">dotWalkedField</span> follows the left-to-right order of fields in a dotwalked form or script.</p> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-addExtraField_S__table_dtk_qcx_hzb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 8. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e854">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e857">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e854 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e857 "><div class="note"><span class="notetitle">Note:</span> The <span class="keyword apiname">addExtraField()</span> method does not impact output results; the output is always the same regardless if you use this method in your script.</div> </td></tr></tbody></table> </div> </div> <div class="example"> <div class="p">The following example shows how to query the contact name field of cmn_location (referenced from the “location” reference field in a cmdb_ci field). <div class="note"><span class="notetitle">Note:</span> The dotWalkedField value in this example, <samp class="ph systemoutput">cmdb_ci.location.contact.name</samp>, looks like “cmdb_ci fields” => “cmn_location fields” => “sys_user fields” in the <span class="ph">ServiceNow®</span> UI when selecting fields in a list.</div> </div> <pre class="pre codeblock"><code>var gliderecord = new GlideRecord("incident"); gliderecord.addQuery("number", "INC0041457"); gliderecord.addExtraField("cmdb_ci.location.contact.name"); gliderecord.query(); gliderecord.next(); gs.print(gliderecord.cmdb_ci.location.contact.name);</code></pre> <p class="p">The output is the same as <code class="ph codeph">gs.print(gr.cmdb_ci.location.contact.name)</code> without using <span class="keyword apiname">addExtraField()</span>. The <span class="keyword apiname">addExtraField()</span> method optimizes the querying of the dot-walked fields. Example output:</p> <pre class="pre codeblock"><code>Abel Tuter</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-addFunction_Object"> <h2 class="title topictitle2" id="ariaid-title6">GlideRecord - addFunction(Object function)</h2> <div class="body refbody"><p class="shortdesc">Applies a pre-defined GlideDBFunctionBuilder object to a record.</p> <div class="section"> <p class="p">Use the GlideDBFunctionBuilder scoped class to define a function. After the function is defined, use the <span class="keyword apiname">addFunction(Object function)</span> method to apply the function to a record.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-addFunction_Object__table_mkh_dnk_kbb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 9. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e981">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e984">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e987">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e981 ">function</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e984 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e987 ">A GlideDBFunctionBuilder or GlideDBCaseStatementBuilder object that defines a SQL operation.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-addFunction_Object__table_nkh_dnk_kbb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 10. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1024">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1027">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1024 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1027 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var functionBuilder = new GlideDBFunctionBuilder(); var myAddingFunction = functionBuilder.add(); myAddingFunction = functionBuilder.field('order'); myAddingFunction = functionBuilder.field('priority'); myAddingFunction = functionBuilder.build(); var now_GR = new GlideRecord('incident'); now_GR.addFunction(myAddingFunction); now_GR.addQuery(myAddingFunction, '<', 5); now_GR.query(); while(now_GR.next()) gs.log(now_GR.getValue(myAddingFunction)); </code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>*** Script: 1 *** Script: 4 *** Script: 3 *** Script: 1 *** Script: 1 *** Script: 2 *** Script: 1 *** Script: 1</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddInactiveQuery"> <h2 class="title topictitle2" id="ariaid-title7">GlideRecord - addInactiveQuery()</h2> <div class="body refbody"><p class="shortdesc">Adds a filter to return inactive records. Inactive records have the active flag set to false.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddInactiveQuery__table_jhb_fnp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 11. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1118">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1121">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1124">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1118 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1121 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1124 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddInactiveQuery__table_khb_fnp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 12. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1159">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1162">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1159 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1162 ">Records where the active flag is false.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var inc = new GlideRecord('incident'); inc.addInactiveQuery(); inc.query();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddInactiveQuery__section_rx1_sbs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">In scoped applications use the scoped method <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddQuery_String_Object" title="Build a search query and return the rows that match the request.">addQuery("active","false")</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddJoinQuery_String"> <h2 class="title topictitle2" id="ariaid-title8">GlideRecord - addJoinQuery(String table)</h2> <div class="body refbody"><p class="shortdesc">Adds a filter to return records based on a relationship in a related table.</p> <div class="section"> <p class="p">For example, find all the users that are in the database group (users via sys_user_grmember table). Another example would be find all problems that have an assigned incident (problems via the incident.problem_id relationship).</p> <p class="p">This is not a true database join; rather, <span class="keyword apiname">addJoinQuery()</span> 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).</p> <p class="p">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 <span class="keyword apiname">insert()</span>, <span class="keyword apiname">update()</span>, <span class="keyword apiname">deleteRecord()</span>, or <span class="keyword apiname">deleteMultiple()</span> method on bad query results can result in data loss.</p> <p class="p">You can set the <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddJoinQuery_String__table_lvg_wnp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 13. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1302">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1305">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1308">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1302 ">table</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1305 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1308 ">Table name</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddJoinQuery_String__table_mvg_wnp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 14. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1346">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1349">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1346 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1349 ">Records where the relationships match.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">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.</p> <pre class="pre codeblock"><code>var prob = new GlideRecord('problem'); prob.addJoinQuery('incident'); prob.query();</code></pre> </div> <div class="example"> <p class="p">Find active=false problems with associated incidents.</p> <pre class="pre codeblock"><code>// Look for Problem records var now_GR = new GlideRecord('problem'); // That have associated Incident records var grSQ = now_GR.addJoinQuery('incident'); // Where the Problem records are "active=false" now_GR.addQuery('active', 'false'); // And the Incident records are "active=true" grSQ.addCondition('active', 'true'); // Query now_GR.query(); // Iterate and print results while (now_GR.next()) { gs.print(now_GR.getValue('number')); }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddJoinQuery_String__section_l1h_vbs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addJoinQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddJoinQuery_String_Object_Object" title="Adds a filter to return records based on a relationship in a table related to the current GlideRecord.">addJoinQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddJoinQuery_String_String"> <h2 class="title topictitle2" id="ariaid-title9">GlideRecord - addJoinQuery(String table, String primaryField)</h2> <div class="body refbody"><p class="shortdesc">Adds a filter to return records based on a relationship in a related table.</p> <div class="section"> <p class="p">For example, find all the users that are in the database group (users via sys_user_grmember table). Another example would be find all problems that have an assigned incident (problems via the incident.problem_id relationship).</p> <p class="p">This is not a true database join; rather, <span class="keyword apiname">addJoinQuery()</span> 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).</p> <p class="p">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 <span class="keyword apiname">insert()</span>, <span class="keyword apiname">update()</span>, <span class="keyword apiname">deleteRecord()</span>, or <span class="keyword apiname">deleteMultiple()</span> method on bad query results can result in data loss.</p> <p class="p">You can set the <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddJoinQuery_String_String__table_es5_y4p_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 15. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1503">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1506">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1509">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1503 ">table</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1506 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1509 ">Table name</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1503 ">primaryField</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1506 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1509 ">If other than sys_id, the primary field.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddJoinQuery_String_String__table_fs5_y4p_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 16. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1559">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1562">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1559 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1562 ">Records where the relationships match.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">Find problems that have incidents using the open_by field at the join key instead of the sys_id.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('problem'); now_GR.addJoinQuery('incident', 'opened_by'); now_GR.query();</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addJoinQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddJoinQuery_String_Object_Object" title="Adds a filter to return records based on a relationship in a table related to the current GlideRecord.">addJoinQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddJoinQuery_String_String_String"> <h2 class="title topictitle2" id="ariaid-title10">GlideRecord - addJoinQuery(String table, String primaryField, String joinTableField)</h2> <div class="body refbody"><p class="shortdesc">Adds a filter to return records based on a relationship in a related table.</p> <div class="section"> <p class="p">For example, find all the users that are in the database group (users via sys_user_grmember table). Another example would be find all problems that have an assigned incident (problems via the incident.problem_id relationship).</p> <p class="p">This is not a true database join; rather, <span class="keyword apiname">addJoinQuery()</span> 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).</p> <p class="p">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 <span class="keyword apiname">insert()</span>, <span class="keyword apiname">update()</span>, <span class="keyword apiname">deleteRecord()</span>, or <span class="keyword apiname">deleteMultiple()</span> method on bad query results can result in data loss.</p> <p class="p">You can set the <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddJoinQuery_String_String_String__table_x3f_rpp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 17. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1708">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1711">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1714">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1708 ">table</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1711 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1714 ">Table name</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1708 ">primaryField</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1711 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1714 ">If other than sys_id, the primary field.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1708 ">joinTableField</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1711 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1714 ">If other than sys_id, the field that joins the tables</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddJoinQuery_String_String_String__table_y3f_rpp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 18. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1776">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1779">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1776 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1779 ">Records where the relationships match.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">Find problems that have incidents associated where the incident caller_id field value matches that of the problem opened_by field.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('problem'); now_GR.addJoinQuery('incident', 'opened_by', 'caller_id'); now_GR.query();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddJoinQuery_String_String_String__section_tjh_zbs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addJoinQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddJoinQuery_String_Object_Object" title="Adds a filter to return records based on a relationship in a table related to the current GlideRecord.">addJoinQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddNotNullQuery_String"> <h2 class="title topictitle2" id="ariaid-title11">GlideRecord - addNotNullQuery(String fieldName)</h2> <div class="body refbody"><p class="shortdesc">Adds a filter to return records where the specified field is not null.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddNotNullQuery_String__table_qkf_3tp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 19. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1887">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1890">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1893">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1887 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1890 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1893 ">The field name.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddNotNullQuery_String__table_rkf_3tp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 20. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1930">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e1933">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1930 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e1933 ">GlideQueryCondition of records where the parameter field is not null.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var target = new GlideRecord('incident'); target.addNotNullQuery('short_description'); target.query(); // Issue the query to the database to get all records while (target.next()) { // add code here to process the incident record }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddNotNullQuery_String__section_kh3_bcs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addNotNullQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddNotNullQuery_String" title="A filter that specifies records where the value of the field passed in the parameter is not null.">addNotNullQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddNullQuery_String"> <h2 class="title topictitle2" id="ariaid-title12">GlideRecord - addNullQuery(String fieldName)</h2> <div class="body refbody"><p class="shortdesc">Adds a filter to return records where the specified field is null.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddNullQuery_String__table_jm5_vtp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 21. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2039">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2042">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2045">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2039 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2042 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2045 ">The field name.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddNullQuery_String__table_km5_vtp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 22. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2082">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2085">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2082 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2085 ">GlideQueryCondition of records where the specified field is null.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var target = new GlideRecord('incident'); target.addNullQuery('short_description'); target.query(); // Issue the query to the database to get all records while (target.next()) { // add code here to process the incident record }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddNullQuery_String__section_n33_dcs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addNullQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddNullQuery_String" title="Adds a filter to return records where the value of the specified field is null.">addNullQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-AddQuery_String_Object_Object"> <h2 class="title topictitle2" id="ariaid-title13">GlideRecord - addQuery(String name, Object operator, Object value)</h2> <div class="body refbody"><p class="shortdesc">Provides the ability to build a request, which when executed, returns the rows from the specified table that match the request.</p> <div class="section"> <p class="p">If you are familiar with SQL, this method is similar to the "where" clause. One or more <span class="keyword apiname">addQuery()</span> calls can be made in a single query; for this method the queries are AND'ed. If any of the query statements need to be OR'ed, use the class <a class="xref" href="../../GlideQueryCondition/concept/c_GlideQueryConditionAPI.html" title="The GlideQueryCondition API provides additional AND or OR conditions that can be added to the current condition, allowing you to build complex queries.">GlideQueryCondition</a>.</p> <p class="p"><span class="keyword apiname">addQuery()</span> is typically called with three parameters; table field, operator, and comparison value. It can be called with only two parameters, table field and comparison value, such as <code class="ph codeph">myObj.addQuery('category','Hardware');</code>. The operator in this case is assumed to be "equal to".</p> <p class="p">For additional information on using queries, see <a class="xref" href="../script/server-scripting/concept/c_UsingGlideRecordToQueryTables.dita/c_UsingGlideRecordToQueryTables.html" target="_blank" rel="noopener noreferrer">Querying tables in script</a>.</p> <p class="p">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 <span class="keyword apiname">insert()</span>, <span class="keyword apiname">update()</span>, <span class="keyword apiname">deleteRecord()</span>, or <span class="keyword apiname">deleteMultiple()</span> method on bad query results can result in data loss.</p> <p class="p">You can set the <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <span class="keyword parmname">glide.invalid_query.returns_no_rows</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddQuery_String_Object_Object__table_ix2_hvp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 23. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2247">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2250">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2253">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2247 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2250 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2253 ">Table field name</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2247 ">operator</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2250 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2253 ">Query operator. The available values are dependent on the data type of the <var class="keyword varname">value</var> parameter.<div class="p">Numbers:<ul class="ul" id="r_GlideRecord-AddQuery_String_Object_Object__ul_qyb_rbt_3y"><li class="li">=</li><li class="li">!=</li><li class="li">></li><li class="li">>=</li><li class="li"><</li><li class="li"><=</li></ul> </div> <div class="p">Strings (must be in upper case):<ul class="ul" id="r_GlideRecord-AddQuery_String_Object_Object__ul_egz_vbt_3y"><li class="li">=</li><li class="li">!=</li><li class="li">IN</li><li class="li">NOT IN</li><li class="li">STARTSWITH</li><li class="li">ENDSWITH</li><li class="li">CONTAINS</li><li class="li">DOES NOT CONTAIN</li><li class="li">INSTANCEOF</li></ul> <div class="note"><span class="notetitle">Note:</span> Use CONTAINS instead of the LIKE operator.</div> </div> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2247 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2250 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2253 ">Value on which to query (not case-sensitive).</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-AddQuery_String_Object_Object__table_jx2_hvp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 24. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2376">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2379">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2376 ">GlideQueryCondition</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2379 ">A reference to the GlideQueryCondition that was added to the GlideRecord.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var rec = new GlideRecord('incident'); rec.addQuery('active',true); rec.addQuery('sys_created_on', ">", "2010-01-19 04:05:00"); rec.query(); while (rec.next()) { rec.active = false; gs.print('Active incident ' + rec.number + ' closed'); rec.update(); }</code></pre> </div> <div class="example"> <p class="p">Using the IN operator.</p> <pre class="pre codeblock"><code>var que = new GlideRecord('incident'); que.addQuery('number','IN','INC00001,INC00002'); que.query(); while(que.next()) { //do something.... }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-AddQuery_String_Object_Object__section_swp_3cs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">addQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordAddQuery_String_String_Object" title="Provides the ability to build a request, which when executed, returns the rows from the specified table, that match the request.">addQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="GlideRecord-addValue_S_N"> <h2 class="title topictitle2" id="ariaid-title14">GlideRecord - addValue(String field, Number value)</h2> <div class="body refbody"><p class="shortdesc">Provides atomic add and subtract operations on a specified number field at the database level for the current GlideRecord object.</p> <div class="section" id="GlideRecord-addValue_S_N__section_myg_ymz_hlb"> <p class="p">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.</p> <div class="p">For example, when the following code is executed, the value of the u_count field in the database is 2.<pre class="pre codeblock"><code>gs.print(now_now_GR.u_count); // "1" now_GR.u_count += 1; now_GR.update(); now_GR.get(now_now_GR.sys_id); gs.print(now_now_GR.u_count); // "2" </code></pre>If another user concurrently runs identical code, instead of the two operations each adding 1 to u_count, the net effect is that u_count only contains 2, with one operation's update actually being lost.</div> <div class="p">Conversely, the <span class="keyword apiname">addValue()</span> method performs the addition/subtraction in the database when the record is updated as an atomic operation. Two operations running concurrently each properly update the field. <pre class="pre codeblock"><code>gs.print(now_now_GR.u_count); // "1" now_GR.addValue("u_count", 1); now_GR.update(); now_GR.get(now_GR); // The record must be reloaded from the database to observe the result gs.print(now_now_GR.u_count); // "3", if executed concurrently with another user </code></pre></div> <div class="p"><div class="note"><span class="notetitle">Note:</span> The new value is not read back from the database unless explicitly done so.</div> </div> <p class="p">Like <span class="keyword apiname">setValue()</span>, <span class="keyword apiname">addValue()</span> changes only take effect in the database after a subsequent call to <span class="keyword apiname">update()</span> or <span class="keyword apiname">insert()</span>. If <span class="keyword apiname">insert()</span> is called, the specified field is initialized with the <span class="keyword parmname">value</span> parameter passed into <span class="keyword apiname">addValue()</span>.</p> <div class="p"><div class="note"><span class="notetitle">Note:</span> If <span class="keyword apiname">setValue()</span> is called for the specified field prior to calling <span class="keyword apiname">addValue()</span>, the <span class="keyword apiname">addValue()</span> method is not processed and an error message is logged.</div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-addValue_S_N__table_h43_tjt_hlb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 25. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2553">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2556">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2559">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2553 ">field</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2556 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2559 ">The name of the field in this GlideRecord to modify. <p class="p">If the associated field is not a numeric type, the operation is ignored.</p> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2553 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2556 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2559 ">The amount to add to the value when the record is saved. To perform a subtraction operation, simply pass a negative value.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-addValue_S_N__table_i43_tjt_hlb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 26. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2610">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2613">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2610 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2613 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">Shows a value being added.</p> <pre class="pre codeblock"><code>gs.print(now_GR.u_count); // "1" now_GR.addValue("u_count", 1); now_GR.update(); now_GR.get(now_GR.sys_id); // The record must be reloaded from the database to observe the result gs.print(now_GR.u_count);</code></pre> <p class="p">Output: 2</p> </div> <div class="example"> <p class="p">Shows a value being subtracted.</p> <pre class="pre codeblock"><code>gs.print(now_GR.u_count); // "4" now_GR.addValue("u_count", -1); now_GR.update(); now_GR.get(now_GR.sys_id); // The record must be reloaded from the database to observe the result gs.print(now_GR.u_count);</code></pre> <p class="p">Output: 3</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="GlideRecord-applyEncodedQuery_S"> <h2 class="title topictitle2" id="ariaid-title15">GlideRecord - applyEncodedQuery(String queryString)</h2> <div class="body refbody"><p class="shortdesc">Sets the values of the specified encoded query terms and applies them to the current GlideRecord.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-applyEncodedQuery_S__table_p5j_nfg_rmb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 27. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2704">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2707">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2710">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2704 ">queryString</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2707 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2710 ">Encoded query to apply to the current GlideRecord.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-applyEncodedQuery_S__table_q5j_nfg_rmb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 28. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2747">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2750">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2747 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2750 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p"></p> <pre class="pre codeblock"><code>function createAcl(table, role) { gs.print("Checking security on table " + table); var now_GR = new GlideRecord("sys_security_acl"); now_GR.addQuery("name", table); now_GR.addQuery("operation", "read"); now_GR.query(); var encQuery = now_GR.getEncodedQuery(); if (now_GR.next()) { // existing acl found so use it createAclRole(now_GR.sys_id.toString(), role); return; } else { now_GR.initialize(); now_GR.applyEncodedQuery(encQuery); var acl = now_GR.insert(); gs.print("Added read access control on " + table); createAclRole(acl, role); } }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-applyTemplate_String"> <h2 class="title topictitle2" id="ariaid-title16">GlideRecord - applyTemplate(String template)</h2> <div class="body refbody"><p class="shortdesc">Apply a template record from the Template table [sys_template] to the current record. If the specified template is not found, no action is taken.</p> <div class="section"> <div class="p"><div class="note"><span class="notetitle">Note:</span> This method automatically instantiates a <span class="keyword apiname">now_GR.insert()</span> method if a template has the <span class="ph uicontrol">Next Related Child Template</span> field filled. For information, see <a class="xref" href="../administer/form-administration/task/create-templates-for-related-task-records.dita/create-templates-for-related-task-records.html" target="_blank" rel="noopener noreferrer">Create templates for related task records</a>.</div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-applyTemplate_String__table_r2n_mlw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 29. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2853">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2856">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2859">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2853 ">template</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2856 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2859 ">Name of a template from the Templates [sys_template] table.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-applyTemplate_String__table_s2n_mlw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 30. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2896">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2899">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2896 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2899 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var rec1 = new GlideRecord("incident"); rec1.initialize(); rec1.applyTemplate("my_incident_template"); rec1.insert();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-autoSysFields_Boolean"> <h2 class="title topictitle2" id="ariaid-title17">GlideRecord - autoSysFields(Boolean e)</h2> <div class="body refbody"><p class="shortdesc">Enables or disables the update to the fields sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on. This is often used for manually updating field values on a record while leaving historical information unchanged.</p> <div class="section"> <div class="p"><div class="note warning"><span class="warningtitle">Warning:</span> Use caution if you use this method. When you use this method the sys_mod_count field will not be incremented, and other sys_ fields will not be updated. This can break functionality including, but not limited to, the Activity Formatter, History Sets, Notifications, and Metrics.</div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-autoSysFields_Boolean__table_t32_tfw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 31. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2988">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2991">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e2994">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2988 ">e</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2991 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e2994 ">If false disables updates to sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-autoSysFields_Boolean__table_u32_tfw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 32. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3031">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3034">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3031 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3034 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var inc = new GlideRecord('incident'); // Change all Open(1) incidents to Active(2) inc.addQuery('state', 1); inc.query(); while (inc.next()) { inc.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on inc.setWorkflow(false); // Do not run any other business rules inc.setValue('state', 2); inc.update(); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-CanCreate"> <h2 class="title topictitle2" id="ariaid-title18">GlideRecord - canCreate()</h2> <div class="body refbody"><p class="shortdesc">Determines if the access control rules (which includes the user's role) permit inserting new records in this table.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanCreate__table_qyz_pwp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 33. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3120">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3123">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3126">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3120 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3123 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3126 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanCreate__table_ryz_pwp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 34. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3161">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3164">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3161 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3164 ">Flag that indicates whether the user's roles permit creating of records in this table.<div class="p">Possible values:<ul class="ul" id="r_GlideRecord-CanCreate__ul_vtm_pf2_t3b"><li class="li">true: Creating permitted</li><li class="li">false: Creating is not permitted</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows whether records can be created on the benefit_plan table.</p> <pre class="pre codeblock"><code>canCreateBenefitPlan : function() { var now_GR = new GlideRecord('benefit_plan'); return now_GR.canCreate(); }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">canCreate()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordCanCreate" title="Determines if the Access Control Rules, which include the user's roles, permit inserting new records in this table.">canCreate()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-CanDelete"> <h2 class="title topictitle2" id="ariaid-title19">GlideRecord - canDelete()</h2> <div class="body refbody"><p class="shortdesc">Determines if the access control rules (which includes the user's role) permit deletion of records in this table.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanDelete__table_kmz_zwp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 35. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3282">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3285">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3288">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3282 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3285 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3288 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanDelete__table_lmz_zwp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 36. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3323">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3326">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3323 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3326 ">Flag that indicates whether the user's roles permit deleting of records in this table.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-CanDelete__ul_vtm_pf2_t3b"><li class="li">true: Deleting permitted</li><li class="li">false: Deleting is not permitted</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var att = new GlideRecord('sys_attachment'); att.get('$[sys_attachment.sys_id]'); var sm = GlideSecurityManager.get(); var checkMe = 'record/sys_attachment/delete'; var canDelete = sm.hasRightsTo(checkMe, att); gs.log('canDelete: ' + canDelete);</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-CanDelete__section_itl_mcs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">canDelete()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordCanDelete" title="Determines if the Access Control Rules, which include the user's roles, permit deleting records in this table.">canDelete()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-CanRead"> <h2 class="title topictitle2" id="ariaid-title20">GlideRecord - canRead()</h2> <div class="body refbody"><p class="shortdesc">Indicates whether the Access Control Rules (ACLs) permit the current user to read the current record within the associated GlideRecord table. This method evaluates all available ACLs for the specific resource.</p> <div class="section"> <div class="p"> <div class="note"><span class="notetitle">Note:</span> You shouldn’t use this method to check for table-level access. A single call to this method might not be sufficient to get a conclusive table-level access rights check result. To perform a table-level access check, use the <span class="keyword apiname">GlideSecurityManager.hasRightsTo()</span> method.</div> </div> <p class="p">For additional information on ACLs, see <a class="xref" href="https://developer.servicenow.com/dev.do#!/learn/learning-plans/yokohama/servicenow_application_developer/app_store_learnv2_securingapps_yokohama_access_controls_evaluation_order" target="_blank" rel="noopener noreferrer">Access Controls Evaluation Order</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanRead__table_c3g_4xp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 37. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3458">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3461">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3464">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3458 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3461 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3464 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanRead__table_d3g_4xp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 38. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3499">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3502">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3499 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3502 ">Flag that indicates whether the user's roles permit reading of the current record.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-CanRead__ul_vtm_pf2_t3b"><li class="li">true: Reading permitted</li><li class="li">false: Reading isn't permitted</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to iterate through the Incident [incident] table and check if the user has read rights to each record.</p> <pre class="pre codeblock"><code>var grTable = new GlideRecord('incident'); grTable.query(); while (grTable.next()) { if (grTable.canRead()) … }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">canRead()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordCanRead" title="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.">canRead()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-CanWrite"> <h2 class="title topictitle2" id="ariaid-title21">GlideRecord - canWrite()</h2> <div class="body refbody"><p class="shortdesc">Determines if the access control rules (which includes the user's role) permit updates to records in this table.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanWrite__table_srp_xxp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 39. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3620">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3623">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3626">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3620 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3623 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3626 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-CanWrite__table_trp_xxp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 40. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3661">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3664">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3661 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3664 ">Flag that indicates whether the user's roles permit writing of records in this table.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-CanWrite__ul_vtm_pf2_t3b"><li class="li">true: Writing permitted</li><li class="li">false: Writing is not permitted</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows whether records can be written to the benefit_plan table.</p> <pre class="pre codeblock"><code>canWriteBenefitPlan : function() { var now_GR = new GlideRecord('benefit_plan'); return now_GR.canWrite(); }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">canWrite()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordCanWrite" title="Determines if the Access Control Rules, which include the user's roles, permit editing records in this table.">canWrite()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-Changes"> <h2 class="title topictitle2" id="ariaid-title22">GlideRecord - changes()</h2> <div class="body refbody"><p class="shortdesc">Determines whether any of the fields in the record have changed.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-Changes__table_ofg_gyp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 41. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3783">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3786">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3789">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3783 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3786 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3789 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-Changes__table_pfg_gyp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 42. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3824">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3827">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3824 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3827 ">Flag that indicates whether there are changes in the specified record.<div class="p">Possible values:<ul class="ul" id="r_GlideRecord-Changes__ul_cqj_2fx_z4b"><li class="li">true: Fields in the specified record have changed.</li><li class="li">false: No fields have changed.</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to check if there are changes in an incident record.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("incident"); now_GR.query(); now_GR.next(); if (now_GR.changes()) { gs.print("The incident record reported changes right after being read"); } else { gs.print("The incident record has not changed"); }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To implement this functionality in a scoped application, add code similar to the following:</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("incident"); now_GR.get("965c9e5347c12200e0ef563dbb9a7156"); now_GR.short_description = "test"; var elements = now_GR.getElements(); var hasChanged = false; for(var i=0; i < elements.length;i++){ var element = elements[i]; hasChanged = hasChanged || element.changes(); gs.info(element.getName() + ":" + element.changes()); } gs.info(hasChanged);</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-deleteMultiple"> <h2 class="title topictitle2" id="ariaid-title23">GlideRecord - deleteMultiple()</h2> <div class="body refbody"><p class="shortdesc">Deletes all records that satisfy the query.</p> <div class="section"> <p class="p">This method does not delete attachments.</p> <p class="p">Dot-walking is not supported for this method. When using the <span class="keyword apiname">deleteMultiple()</span> function on referenced tables, all the records in the table are deleted. Also, when using <span class="keyword apiname">deleteRecord()</span> to cascade delete, prior calls to <span class="keyword apiname">setWorkflow()</span> on the same GlideRecord object are ignored.</p> <p class="p">Do not use <span class="keyword apiname">deleteMultiple()</span> on tables with currency fields. Always delete each record individually. Also, do not use this method with the <span class="keyword apiname">chooseWindow()</span> or <span class="keyword apiname">setLimit()</span> methods when working with large tables. The <span class="keyword apiname">setLimit()</span> method does not limit the number of records that are deleted with <span class="keyword apiname">deleteMultiple()</span>. All records returned by the query are deleted regardless of <span class="keyword apiname">setLimit()</span>.</p> <p class="p">The <span class="keyword parmname">glide.db.forced.chunk.threshold</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> <div class="p"> <div class="note"><span class="notetitle">Note:</span> When using <span class="keyword apiname">deleteMultiple()</span> to cascade delete, prior calls to <span class="keyword apiname">setWorkflow()</span> on the same GlideRecord object are ignored.</div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-deleteMultiple__table_ck5_g1x_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 43. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e3998">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4001">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4004">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e3998 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4001 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4004 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-deleteMultiple__table_dk5_g1x_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 44. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4039">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4042">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4039 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4042 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-deleteMultiple__example_opm_23t_bzb"> <p class="p">This example shows how to delete all inactive records from the Incident table.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); now_GR.addQuery('active','false'); now_GR.query(); now_GR.deleteMultiple();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-deleteMultiple__section_gy3_zcs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">deleteMultiple()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordDeleteMultiple" title="Deletes all records that satisfy the query.">deleteMultiple()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-deleteRecord"> <h2 class="title topictitle2" id="ariaid-title24">GlideRecord - deleteRecord()</h2> <div class="body refbody"><p class="shortdesc">Deletes a single record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-deleteRecord__table_xqy_s1x_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 45. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4150">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4153">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4156">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4150 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4153 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4156 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-deleteRecord__table_yqy_s1x_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 46. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4191">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4194">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4191 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4194 ">Flag that indicates whether the record was successfully deleted.<div class="p">Possible values:<ul class="ul" id="r_GlideRecord-deleteRecord__ul_hkn_5bj_s3b"><li class="li">true: Record was deleted.</li><li class="li">false: No record was found to delete.</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to delete all inactive records from the Incident table.</p> <pre class="pre codeblock"><code>var rec = new GlideRecord('incident'); rec.addQuery('active',false); rec.query(); while (rec.next()) { gs.info('Inactive incident ' + rec.number + ' deleted'); rec.deleteRecord(); }</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Inactive incident INC0010010 deleted Inactive incident INC0010011 deleted</code></pre> </div> <div class="example" id="r_GlideRecord-deleteRecord__example_tg2_ztl_bzb"> <p class="p">This example shows how to delete a record from the Incident table immediately after it is inserted. The incident <span class="keyword apiname">GlideRecord</span> must be reloaded after the insert before it can be deleted.</p> <pre class="pre codeblock"><code>var grTicket = new GlideRecord('incident'); grTicket.initialize(); grTicket.short_description = 'Example ticket'; grTicket.work_notes = 'An update about the ticket'; var ins_sys_id = grTicket.insert(); // Insert the record grTicket.get(ins_sys_id); // Reload the inserted record gs.info(grTicket.deleteRecord()); // Delete the record</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>true</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-deleteRecord__section_h4z_1ds_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">deleteRecord()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordDeleteRecord" title="Deletes the current record.">deleteRecord()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="GR-disableSysIdInOptimization"> <h2 class="title topictitle2" id="ariaid-title25">GlideRecord - disableSysIdInOptimization()</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">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 <code class="ph codeph">grIncident.addQuery('sys_id', 'IN', listOf200SysIds)</code>. </span></p> <div class="section"> <p class="p">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 <span class="keyword parmname">glide.db.first_pass_sys_id_list_size.max</span> system property (default 100).</p> <p class="p">If you don't either call this method or adjust the <span class="keyword parmname">glide.db.first_pass_sys_id_list_size.max</span> system property and pass a list that contains more sys_id entries than defined in <span class="keyword parmname">glide.db.first_pass_sys_id_list_size.max</span>, the returned value from <span class="keyword apiname">GlideRecord.getRowCount()</span> may be incorrect.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GR-disableSysIdInOptimization__table_ilp_2cg_zcc" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 47. </span>Parameters</span></caption><colgroup><col style="width:16.666666666666664%" /><col style="width:16.666666666666664%" /><col style="width:66.66666666666666%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4346">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4349">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4352">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4346 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4349 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4352 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GR-disableSysIdInOptimization__table_jlp_2cg_zcc" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 48. </span>Returns</span></caption><colgroup><col style="width:25%" /><col style="width:75%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4387">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4390">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4387 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4390 "> </td></tr></tbody></table> </div> </div> <div class="example" id="GR-disableSysIdInOptimization__id_btq_dhg_zcc"> <p class="p">The following code example shows how to use the <span class="keyword apiname">disableSysIdInOptimiation()</span> method to disable the sys_id limit optimization when passing an Incident sys_id list that contains 200 entries.</p> <pre class="pre codeblock"><code>var listOf200SysIds = [ ... ]; // 200 comma separated sys_ids var grIncident = new GlideRecord('incident'); grIncident.addQuery('sys_id', 'IN', listOf200SysIds); grIncident.disableSysIdInOptimization(); // Rowcount could be incorrect without this method call grIncident.query(); if (grIncident.next()) gs.info("Rowcount: " + grIncident.getRowCount());</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Rowcount: 200</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-Find_String_String"> <h2 class="title topictitle2" id="ariaid-title26">GlideRecord - find(String columnName, String value)</h2> <div class="body refbody"><p class="shortdesc">Returns true if any record has a matching value in the specified column. If found, it also moves to the first record that matches, essentially executing <span class="keyword apiname">next()</span> until the record is returned.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-Find_String_String__table_k1m_qyp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 49. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4491">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4494">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4497">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4491 ">columnName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4494 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4497 ">Field name to search.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4491 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4494 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4497 ">Value to check for in the specified field.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-Find_String_String__table_l1m_qyp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 50. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4546">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4549">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4546 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4549 ">Flag that indicates whether any record within the current table has a matching value in the specified field.<div class="p">Possible values:<ul class="ul"><li class="li">true: Matching field.</li><li class="li">false: No matching field.</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to find a record in the Incident table with "Critical" in the short description field.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("incident"); now_GR.query(); var shortDescription = "Critical"; if (now_GR.find("short_description", shortDescription)) { gs.print("An incident with the specified field value was found"); var recordID = now_GR.getValue("sys_id"); gs.print("Found in the following record: " + recordID); } else { gs.print("An incident with the specified field value was not found"); }</code></pre> <p class="p">Output</p> <pre class="pre codeblock"><code>An incident with the specified field value was found Found in the following record: 552c48888c033300964f4932b03eb092</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-get_Object_Object"> <h2 class="title topictitle2" id="ariaid-title27">GlideRecord - get(Object name, Object value)</h2> <div class="body refbody"><p class="shortdesc">Returns the specified record in the current GlideRecord object.</p> <div class="section"> <p class="p">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 <span class="keyword apiname">next()</span> to access the additional records.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-get_Object_Object__table_bwp_pcr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 51. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4660">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4663">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4666">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4660 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4663 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4666 ">Optional. Name of the instantiated GlideRecord column to search for the specified <span class="keyword parmname">value</span> parameter. If only a single parameter is passed in, the method assumes that this parameter is sys_id.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4660 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4663 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4666 ">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.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-get_Object_Object__table_cwp_pcr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 52. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4718">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4721">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4718 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4721 ">Indicates whether the requested record was located.<div class="p">Possible values:<ul class="ul" id="r_GlideRecord-get_Object_Object__ul_ngs_clw_qfb"><li class="li">true: Record was found</li><li class="li">false: Record was not found</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example gets an incident record by passing in the sys_id.</p> <pre class="pre codeblock"><code>var grIncident = new GlideRecord('incident'); var returnValue = grIncident.get('99ebb4156fa831005be8883e6b3ee4b9'); gs.info(returnValue); // logs true or false gs.info(grIncident.number); // logs Incident Number</code></pre> </div> <div class="example"> <p class="p">This example gets an incident record by passing in the column in the record to search and the value to search for.</p> <pre class="pre codeblock"><code>var grIncident = new GlideRecord('incident'); var returnValue = grIncident.get('caller_id.name','Sylivia Wayland'); gs.info(returnValue); // logs true or false gs.info(grIncident.number); // logs Incident Number</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-get_Object_Object__section_rcl_s2s_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">get()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGet_Object_Object" title="Returns the specified record in the current GlideRecord object.">get()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getAttribute_String"> <h2 class="title topictitle2" id="ariaid-title28">GlideRecord - getAttribute(String fieldName)</h2> <div class="body refbody"><p class="shortdesc">Returns the dictionary attributes on the specified field.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getAttribute_String__table_b2b_jdr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 53. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4849">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4852">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4855">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4849 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4852 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4855 ">Field name for which to return the dictionary attributes</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getAttribute_String__table_c2b_jdr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 54. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4892">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e4895">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4892 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e4895 ">Dictionary attributes</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to return the dictionary attributes for "tree_picker".</p> <pre class="pre codeblock"><code>function doit() { var now_GR = new GlideRecord('sys_user'); now_GR.query("user_name","admin"); if (now_GR.next()) { gs.print("we got one"); gs.print(now_GR.location.getAttribute("tree_picker")); } }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getAttribute_String__section_bmb_dds_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getAttribute()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#SGR-getAttribute_S" title="Returns the dictionary attributes for the specified field.">getAttribute()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getClassDisplayValue"> <h2 class="title topictitle2" id="ariaid-title29">GlideRecord - getClassDisplayValue()</h2> <div class="body refbody"><p class="shortdesc">Returns the table's label.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getClassDisplayValue__table_ltd_ydr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 55. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5003">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5006">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5009">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5003 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5006 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5009 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getClassDisplayValue__table_mtd_ydr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 56. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5044">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5047">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5044 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5047 ">Label that identifies the table.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example prints the label of the passed in table.</p> <pre class="pre codeblock"><code>// Display the incident table label var now_GR = new GlideRecord("incident"); var value = now_GR.getClassDisplayValue(); gs.info("The table label is " + value + ".");</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>The table label is Incident.</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getClassDisplayValue()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#SGR-getClassDisplayValue" title="Returns the current table's label.">getClassDisplayValue()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getDisplayValue"> <h2 class="title topictitle2" id="ariaid-title30">GlideRecord - getDisplayValue()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the display value for the current record.</p> <div class="section"> <p class="p">Display values are manipulated based on the actual value in the database and user or system settings and preferences.</p> <div class="p">The display value that is returned is dependent on the field type. <ul class="ul" id="r_GlideRecord-getDisplayValue__ul_ok1_cbv_hsb"><li class="li">Choice fields: The database value may be a number, but the display value will be more descriptive.</li><li class="li">Date fields: The database value is in UTC format, while the display value is based on the user's time zone.</li><li class="li">Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.</li><li class="li">Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.</li></ul> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getDisplayValue__table_kps_f2r_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 57. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5182">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5185">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5188">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5182 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5185 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5188 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getDisplayValue__table_lps_f2r_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 58. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5223">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5226">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5223 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5226 ">Display value for the current record.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example writes the display value of a specified incident record into the log.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); now_GR.get('sys_id','<sys_id>'); gs.info(now_GR.getDisplayValue());</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>INC0000050</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getDisplayValue__section_j51_nds_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getDisplayValue()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetDisplayValue" title="Retrieves the display value for the current record.">getDisplayValue()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getED"> <h2 class="title topictitle2" id="ariaid-title31">GlideRecord - getED()</h2> <div class="body refbody"><p class="shortdesc">Returns the element's descriptor.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getED__table_ppq_p2r_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 59. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5340">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5343">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5346">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5340 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5343 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5346 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getED__table_qpq_p2r_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 60. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5381">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5384">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5381 ">GlideElementDescriptor</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5384 ">The element's descriptor.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to retrieve the name field for an incident GlideRecord.</p> <pre class="pre codeblock"><code>grInc = new GlideRecord('incident'); grInc.getActiveQuery(); grInc.query(); if (grInc.next()) gs.info("Table Descriptor is - " + grInc.getED().getName()); </code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Table Descriptor is - incident</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getED__section_vj2_pds_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getED()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#SGR-getED" title="Returns the element's descriptor.">getED()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getElement_String"> <h2 class="title topictitle2" id="ariaid-title32">GlideRecord - getElement(String fieldName)</h2> <div class="body refbody"><p class="shortdesc">Retrieves the GlideElement for a specified field.</p> <div class="section"> <p class="p">The value returned by this method is a complete GlideElement object. The results are the equivalent of dot-walking a field value. For example, <code class="ph codeph">now_GR.getElement('short_description')</code> provides the same result as <code class="ph codeph">nowGR.short_description</code>.</p> <p class="p">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 <span class="ph">Service Portal</span>.</p> <p class="p">Instead of retrieving the entire object, you can use one of the following methods to copy the field values:</p> <div class="p"><ul class="ul" id="r_GlideRecord-getElement_String__gr-api-dot-walk-global-rec-lnx"><li class="li"><a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-getValue_String" title="Retrieves the string value of a specified field.">getValue()</a></li><li class="li"><a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-getDisplayValue" title="Retrieves the display value for the current record.">getDisplayValue()</a></li></ul> </div> <div class="p">If dot-walking through a GlideElement object is necessary, use the <span class="keyword apiname">toString()</span> method to retrieve values. For example, you might need the current caller's manager sys_id to set another reference field. The following example shows how to get the string value instead of the entire object:<pre class="pre codeblock"><code>var mgr = current.caller_id.manager.toString();</code></pre></div> <p class="p">See also: <a class="xref" href="../../GlideElement_global/concept/c_GlideElementAPI.html#r_GlideElement-toString" title="Converts the field's value to a string.">GlideElement - toString()</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getElement_String__id_rmz_rpn_mpb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 61. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5556">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5559">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5562">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5556 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5559 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5562 ">Column name for which to return the GlideElement object.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getElement_String__table_yxw_bfr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 62. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5599">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5602">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5599 ">GlideElement</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5602 ">The GlideElement for the specified column of the current record. Each object describes a field in the current GlideRecord.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to obtain the GlideElement object for a passed in table and compare them with the expected system metadata values.</p> <pre class="pre codeblock"><code>function compareElement(comment, table, element, /*{}*/ expected) { var now_GR = new GlideRecord(table); var el = now_GR.getElement(element); for (var n in expected) { assertEquals(comment + ":" + table + "." + element, expected[n], el.sys_meta[n]); } }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getElement()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetElement_String" title="Retrieves the GlideElement object for the specified field.">getElement()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getEncodedQuery_Boolean"> <h2 class="title topictitle2" id="ariaid-title33">GlideRecord - getEncodedQuery()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the query condition of the current result set as an encoded query string.</p> <div class="section"> <p class="p">For details, see <span class="ph" id="r_GlideRecord-getEncodedQuery_Boolean__link_encoded_query_strings"> <a class="xref" href="../use/using-lists/concept/c_EncodedQueryStrings.dita/c_EncodedQueryStrings.html" target="_blank" rel="noopener noreferrer">Encoded query strings</a> </span>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getEncodedQuery_Boolean__table_ng2_mfr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 63. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5720">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5723">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5726">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5720 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5723 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5726 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getEncodedQuery_Boolean__table_og2_mfr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 64. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5761">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5764">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5761 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5764 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to obtain the current encoded query to use later to create a read ACL role.</p> <pre class="pre codeblock"><code>function createAcl(table, role) { gs.print("Checking security on table " + table); var now_GR = new GlideRecord("sys_security_acl"); now_GR.addQuery("name", table); now_GR.addQuery("operation", "read"); now_GR.query(); var encQuery = now_GR.getEncodedQuery(); if (now_GR.next()) { // existing acl found so use it createAclRole(now_GR.sys_id.toString(), role); return; } else { now_GR.initialize(); now_GR.applyEncodedQuery(encQuery); var acl = now_GR.insert(); gs.print(" Added read access control on " + table); createAclRole(acl, role); } }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getEncodedQuery()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetEncodedQuery" title="Retrieves the query condition of the current result set as an encoded query string.">getEncodedQuery()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getEscapedDisplayValue"> <h2 class="title topictitle2" id="ariaid-title34">GlideRecord - getEscapedDisplayValue()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the field value for the display field of the current record and adds escape characters for use in Jelly scripts.</p> <div class="section"> <div class="p"><div class="note"><span class="notetitle">Note:</span> For this method to work, a display value must have been set on the associated table. For information on how to do this, see <a class="xref" href="../administer/field-administration/task/t_SelectTheDisplayValue.dita/t_SelectTheDisplayValue.html" target="_blank" rel="noopener noreferrer">Select a field as the table display value</a>.</div> </div> </div> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getEscapedDisplayValue__table_xcp_5fr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 65. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5884">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5887">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5890">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5884 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5887 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5890 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getEscapedDisplayValue__table_ycp_5fr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 66. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5925">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e5928">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5925 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e5928 ">Escaped value of the current table's display field.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to obtain the user_name escaped display value from the User [sys_user] table.</p> <pre class="pre codeblock"><code>var userName = "Michael J'ones"; var now_GR = new GlideRecord("sys_user"); if (now_GR.get("user_name", userName)) { gs.print("Deleting existing user=" + userName); now_GR.deleteRecord(); } now_GR.initialize(); var name = userName.split(" ", 2); var firstName = name[0]; var lastName = name[1]; now_GR.setValue("user_name", userName); gs.print("Name: " + now_GR.getValue("user_name")); now_GR.setValue("first_name", firstName); now_GR.setValue("last_name", lastName); var escapeValue = now_GR.getEscapedDisplayValue(); gs.print("Escaped name: " + escapeValue);</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Name: Michael J'ones Escaped name: Michael J\'ones</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getFields"> <h2 class="title topictitle2" id="ariaid-title35">GlideRecord - getFields()</h2> <div class="body refbody"><p class="shortdesc">Retrieves a Java ArrayList of fields in the current record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getFields__table_yzn_fgr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 67. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6023">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6026">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6029">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6023 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6026 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6029 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getFields__table_zzn_fgr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 68. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6064">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6067">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6064 ">Java ArrayList</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6067 ">Fields in the current record</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>// This can be run in "Scripts - Background" for demonstration purposes // Get a single incident record var grINC = new GlideRecord('incident'); grINC.query(); grINC.next(); gs.print('Using ' + grINC.getValue('number')); gs.print(''); // getFields() returns a Java ArrayList var fields = grINC.getFields(); // Enumerate GlideElements in the GlideRecord object that have values gs.print('Enumerating over all fields with values:'); for (var i = 0; i < fields.size(); i++) { var glideElement = fields.get(i); if (glideElement.hasValue()) { gs.print(' ' + glideElement.getName() + '\t' + glideElement); } } gs.print(''); // Get a specific GlideElement: number gs.print('Getting the number field:'); for (var i = 0; i < fields.size(); i++) { var glideElement = fields.get(i); if (glideElement.hasValue() && glideElement.getName() == 'number') { gs.print(' ' + glideElement.getName() + '\t' + glideElement); } }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getLabel"> <h2 class="title topictitle2" id="ariaid-title36">GlideRecord - getLabel()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the field's label.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getLabel__table_ajl_sgr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 69. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6154">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6157">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6160">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6154 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6157 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6160 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getLabel__table_bjl_sgr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 70. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6195">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6198">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6195 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6198 ">The field's label</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to retrieve a label of a question field in the Requested Item table and print the label and its display name.</p> <pre class="pre codeblock"><code>template.print("Summary of Requested items:\n"); var now_GR = new GlideRecord("sc_req_item"); now_GR.addQuery("request", current.sysapproval); now_GR.query(); while(now_GR.next()) { var nicePrice = now_GR.price.toString(); if (nicePrice != '') { nicePrice = parseFloat(nicePrice); nicePrice = nicePrice.toFixed(2); } template.print(now_GR.number + ": " + now_GR.quantity + " X " + now_GR.cat_item.getDisplayValue() + " at $" + nicePrice + " each \n"); template.print(" Options:\n"); for (key in now_GR.variables) { var now_V = now_GR.variables[key]; if(now_V.getGlideObject().getQuestion().getLabel() != '') { template.space(4); template.print(' ' + now_V.getGlideObject().getQuestion().getLabel() + " = " + vnow_V.getDisplayValue() + "\n"); } } }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getLabel__section_bdc_d2s_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getLabel()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#SGR-getLabel" title="Returns the field's label.">getLabel()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getLink_Boolean"> <h2 class="title topictitle2" id="ariaid-title37">GlideRecord - getLink(Boolean noStack)</h2> <div class="body refbody"><p class="shortdesc">Retrieves the link for the current record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getLink_Boolean__table_evz_2hr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 71. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6306">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6309">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6312">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6306 ">noStack</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6309 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6312 ">Flag that indicates whether to append the generated link to the end of the URL. For example: <code class="ph codeph">&sysparm_stack=[tablename]_list.do? sysparm_query=active=true</code>.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-getLink_Boolean__ul_jwg_kmt_ymb"><li class="li">true: Append link.</li><li class="li">false: Do not append link.</li></ul> </div> <p class="p">Default: false</p> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getLink_Boolean__table_fvz_2hr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 72. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6365">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6368">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6365 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6368 ">URL of the current record.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks for attachments and adds the link if any are found.</p> <pre class="pre codeblock"><code>var attachment_link = ''; var rec = new GlideRecord('sc_req_item'); rec.addQuery('sys_id', current.request_item); rec.query(); if(rec.next()){ if(rec.hasAttachments()){ attachment_link = gs.getProperty('glide.servlet.uri') + rec.getLink(); } }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getLink_Boolean__section_qvr_f2s_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getLink()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetLink_Boolean" title="Retrieves the link to the current record.">getLink()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getLocation_Boolean"> <h2 class="title topictitle2" id="ariaid-title38">GlideRecord - getLocation()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the row number of the current record within the table.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getLocation_Boolean__table_hzq_whr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 73. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6477">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6480">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6483">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6477 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6480 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6483 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getLocation_Boolean__table_izq_whr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 74. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6518">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6521">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6518 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6521 ">Zero-based row number of the current record within the table.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to check if a record within the Incident table is not retrieved properly by comparing the record count to the record location number.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("incident"); now_GR.addQuery("priority", "4"); now_GR.query(); for (x=0; x <4; x++) { now_GR.next(); gs.print("Location value: " + now_GR.getLocation()); }</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Location value: 0 Location value: 1 Location value: 2 Location value: 3</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getPlural"> <h2 class="title topictitle2" id="ariaid-title39">GlideRecord - getPlural()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the plural label of the GlideRecord table.</p> <div class="section"> <p class="p">For example, if the table name is "Change Request," this method returns "Change Requests."</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getPlural__table_pfl_g3r_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 75. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6619">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6622">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6625">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6619 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6622 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6625 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getPlural__table_qfl_g3r_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 76. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6660">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6663">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6660 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6663 ">The plural label of the GlideRecord's table.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows checks the return values for <span class="keyword apiname">getLabel()</span> and <span class="keyword apiname">getPlural()</span> for the Incident table.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); gs.print(now_GR.getLabel()); if (now_GR.getLabel() != 'Incident') throw "GlideRecord.getLabel() returned unexpected value for table 'incident': " + now_GR.getLabel(); gs.print(now_GR.getPlural()); if (now_GR.getPlural() != 'Incidents') throw "GlideRecord.getPlural() returned unexpected value for table 'incident': " + now_GR.getPlural(); "success";</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getPlural__section_itl_mcs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getPlural()</span> method in a scoped application, use the scoped <a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-getED" title="Returns the element's descriptor.">GlideRecord.getED()</a> method to obtain the field's descriptor, and then use the scoped <a class="xref" href="../../glideElementDescriptor/concept/c_GlideElementDescriptorScopedAPI.html#r_SGED-getPlural" title="Returns the element's plural label.">GlideElementDescriptor.getPlural()</a> method.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getRecordClassName"> <h2 class="title topictitle2" id="ariaid-title40">GlideRecord - getRecordClassName()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the class (table) name for the current record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRecordClassName__table_dxr_r3r_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 77. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6784">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6787">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6790">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6784 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6787 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6790 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRecordClassName__table_exr_r3r_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 78. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6825">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6828">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6825 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6828 ">Class or table name</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>function TaskAssignmentFilter() { var classname = current.getRecordClassName(); var filter = "type=null"; if (classname == "incident" && current.category == "database") { filter = GetGroupFilter("database"); } else { // append exclusion for 'catalog' to the filter var cat = new GlideRecord("sys_user_group_type"); cat.addQuery("name", "catalog"); cat.query(); if (cat.next()) { filter += "^ORtype!=" + cat.sys_id; } } gs.log("TaskAssignmentFilter: " + filter); return filter; }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getRecordClassName__section_nrs_h2s_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getRecordClassName()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetRecordClassName" title="Retrieves the class name for the current record.">getRecordClassName()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getRelatedLists_Boolean"> <h2 class="title topictitle2" id="ariaid-title41">GlideRecord - getRelatedLists()</h2> <div class="body refbody"><p class="shortdesc">Retrieves a list of names and display values of related lists associated with the current GlideRecord.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRelatedLists_Boolean__table_f2p_3jr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 79. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6933">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6936">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6939">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6933 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6936 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6939 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRelatedLists_Boolean__table_g2p_3jr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 80. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6974">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e6977">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6974 ">HashMap</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e6977 ">Hash map with names and display values of related lists.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to obtain the list of names and display values of related lists associated with the current GlideRecord, store them in an array, and then print their values.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); var c = now_GR.getRelatedLists().values().toArray(); var numElements = c.length; for( var i = 0; i < numElements; ++i){ gs.print(i+": "+c[i]); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getRelatedTables_Boolean"> <h2 class="title topictitle2" id="ariaid-title42">GlideRecord - getRelatedTables()</h2> <div class="body refbody"><p class="shortdesc">Retrieves a list of names and display values of tables that are referred to by the current record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRelatedTables_Boolean__table_lwm_vjr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 81. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7067">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7070">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7073">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7067 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7070 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7073 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRelatedTables_Boolean__table_mwm_vjr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 82. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7108">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7111">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7108 ">HashMap</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7111 ">Hash map with names and display values of related tables.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to obtain the list of names and display values of tables related to the current GlideRecord, store them in an array, and then print their values.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); var c = now_GR.getRelatedTables().values().toArray(); var numElements = c.length; for( var i = 0; i < numElements; ++i){ gs.print(i+": "+c[i]); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getRowCount"> <h2 class="title topictitle2" id="ariaid-title43">GlideRecord - getRowCount()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the number of rows (records) in the current GlideRecord object.</p> <div class="section" id="r_GlideRecord-getRowCount__id_xl1_mrn_nyb"> <div class="note"><span class="notetitle">Note:</span> <span class="keyword apiname">GlideRecord</span> returns matching records, so it might not be as efficient as <span class="keyword apiname">GlideAggregate</span> when you only need the number of records. If you only need a record count and aren’t iterating over the matching records, use <span class="keyword apiname">GlideAggregate</span>.</div> <div class="p"><dl class="dl parml"> <dt class="dt pt dlterm">Retrieving the number records in GlideRecord or GlideAggregate</dt> <dd class="dd pd">The <span class="keyword apiname">GlideRecord getRowCount()</span> and <a class="xref" href="../../glideAggregateScoped/concept/c_GlideAggregateScopedAPI.html" title="GlideAggregate enables creating database aggregation queries."><span class="keyword apiname">GlideAggregate getAggregate()</span></a> APIs offer similar information. Use the following criteria to determine which option is best for you. <ul class="ul" id="r_GlideRecord-getRowCount__ul_wdq_fmn_nyb"><li class="li">The <span class="keyword apiname">GlideRecord getRowCount()</span> 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.</li><li class="li">The <span class="keyword apiname">GlideAggregate getAggregate()</span> method retrieves only a count of records matching the query, excluding the actual records. The aggregate must be set on the <span class="keyword apiname">GlideAggregate</span> object prior to issuing the query.</li></ul> </dd> <dd class="dd pd ddexpand">Retrieving the records and count with GlideRecord getRowCount()<div class="p">The following example shows how to get the total number of active incidents with <span class="keyword apiname">GlideRecord getRowCount()</span>:<pre class="pre codeblock"><code>var incident = new GlideRecord("incident"); incident.addQuery("active", true); incident.query(); gs.info("*** Total number of active incidents: {0}", incident.getRowCount());</code></pre></div> </dd> <dd class="dd pd ddexpand">Retrieving only the number of records with GlideAggregate getAggregate()<div class="p">The following example shows how to return only the number of records. Because this method doesn’t use the matching records, it’s much more efficient to use an aggregate query and return just the count.<pre class="pre codeblock"><code>var incident = new GlideAggregate("incident"); incident.addQuery("active", true); incident.addAggregate("COUNT"); incident.query(); if (incident.next()) gs.info("*** Total number of active incidents: {0}", incident.getAggregate("COUNT"));</code></pre></div> </dd> <dd class="dd pd ddexpand">Deciding which option is best for your solution<p class="p">If you only want to retrieve the number of records, the <span class="keyword apiname">GlideAggregate getAggregate()</span> method is the best option. To use the individual records and retrieve the number of results, use <span class="keyword apiname">GlideRecord getRowCount()</span>, because a single query provides this functionality.</p> </dd> </dl> </div> <div class="p"> <div class="note"><span class="notetitle">Note:</span> If you want to use the <span class="keyword apiname">getRowCount()</span> method when using <code class="ph codeph">sys_id IN</code> with more than 100 sys_id values, such as <code class="ph codeph">grIncident.addQuery('sys_id', 'IN', listOf200SysIds)</code>, you must either: <ul class="ul" id="r_GlideRecord-getRowCount__ul_j1v_ztm_zcc"><li class="li">Call the <span class="keyword apiname">disableSysIdInOptimization()</span> method on the GlideRecord.</li><li class="li">Or, adjust the <span class="keyword parmname">glide.db.first_pass_sys_id_list_size.max</span> system property to a value higher than the number of sys_ids in the list.</li></ul> In addition, ensure that you call the <span class="keyword apiname">.next()</span> method before calling the <span class="keyword apiname">getRowCount()</span> method. </div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRowCount__table_dxv_hkr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 83. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7324">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7327">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7330">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7324 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7327 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7330 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRowCount__table_exv_hkr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 84. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7365">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7368">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7365 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7368 ">Number of rows in the current GlideRecord.</td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-getRowCount__id_sk4_mrn_nyb"> <p class="p">The following example shows how to get the number of incidents from the Incident [incident] table.</p> <pre class="pre codeblock"><code>var numberOfIncidents = new GlideRecord('incident'); numberOfIncidents.query(); gs.info("Records in incident table: " + numberOfIncidents.getRowCount());</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Records in incident table: 6920</code></pre> </div> <div class="example" id="r_GlideRecord-getRowCount__id_n3z_d4g_zcc"> <p class="p">The following code example shows how to use the <span class="keyword apiname">disableSysIdInOptimiation()</span> method to disable the sys_id limit optimization when passing an Incident sys_id list that contains 200 entries.</p> <pre class="pre codeblock"><code>var listOf200SysIds = [ ... ]; // 200 comma separated sys_ids var grIncident = new GlideRecord('incident'); grIncident.addQuery('sys_id', 'IN', listOf200SysIds); grIncident.disableSysIdInOptimization(); // Rowcount could be incorrect without this method call grIncident.query(); if (grIncident.next()) gs.info("Rowcount: " + grIncident.getRowCount());</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Rowcount: 200</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getRowCount()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetRowCount" title="Retrieves the number of rows (records) in the current GlideRecord object.">getRowCount()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getRowNumber"> <h2 class="title topictitle2" id="ariaid-title44">GlideRecord - getRowNumber()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the row number set by <span class="keyword apiname">saveLocation()</span> or <span class="keyword apiname">setLocation()</span>.</p> <div class="section"> <p class="p">To get the current row number, use <span class="keyword apiname">getLocation()</span>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRowNumber__table_m4c_pkr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 85. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7513">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7516">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7519">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7513 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7516 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7519 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getRowNumber__table_n4c_pkr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 86. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7554">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7557">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7554 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7557 ">Saved row number.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to save a row location in the Users table and then obtain that row number.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('sys_user'); now_GR.addQuery(); now_GR.query(); now_GR.saveLocation(5); var savedRow = now_GR.getRowNumber(); gs.print("Saved row: " + savedRow);</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Saved row: 5</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getTableName"> <h2 class="title topictitle2" id="ariaid-title45">GlideRecord - getTableName()</h2> <div class="body refbody"><p class="shortdesc">Retrieves the table name associated with this GlideRecord.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getTableName__table_hcx_wkr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 87. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7652">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7655">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7658">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7652 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7655 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7658 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getTableName__table_icx_wkr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 88. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7693">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7696">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7693 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7696 ">A table name</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to write the current table name in the system log.</p> <pre class="pre codeblock"><code>gs.log('Table: ' + current.getTableName()); gs.log('Parent: ' + current.parent.sys_id); var item = new GlideRecord('sc_req_item'); item.addQuery('sys_id', current.parent.sys_id); item.query(); if(item.next()){ for(var variable in item.variable_pool) { gs.log(variable); var answer = eval ("item.variable_pool." + variable + ".getDisplayValue()"); gs.log(answer); } }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-getTableName__section_hfr_42s_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getTableName()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetTableName" title="Retrieves the name of the table associated with the GlideRecord.">getTableName()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="GlideRecord-getUniqueValue_S"> <h2 class="title topictitle2" id="ariaid-title46">GlideRecord - getUniqueValue()</h2> <div class="body refbody"><p class="shortdesc">Gets the primary key of the record, which is usually the sys_id unless otherwise specified.</p> <div class="section" id="GlideRecord-getUniqueValue_S__section_q1r_jyd_g5b"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-getUniqueValue_S__table_t5k_btb_2r" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 89. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7805">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7808">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7811">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7805 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7808 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7811 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GlideRecord-getUniqueValue_S__table_qpt_3f5_jq" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 90. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7846">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7849">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7846 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7849 ">The unique primary key as a String, or null if the key is null.</td></tr></tbody></table> </div> </div> <div class="example" id="GlideRecord-getUniqueValue_S__example_r1r_jyd_g5b"> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('kb_knowledge'); now_GR.query(); now_GR.next(); var uniqueid = now_GR.getUniqueValue(); gs.info(uniqueid);</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-getValue_String"> <h2 class="title topictitle2" id="ariaid-title47">GlideRecord - getValue(String fieldName)</h2> <div class="body refbody"><p class="shortdesc">Retrieves the string value of a specified field.</p> <div class="section"> <div class="p"><div class="note"><span class="notetitle">Note:</span> If the <span class="ph">Column Level Encryption</span> Enterprise plugin is enabled and the instance has access to the key, this method returns clear text values from encrypted fields. If the instance does not have access to the key, this method returns the encrypted value. For more information, see <a class="xref" href="../administer/now-platform-encryption/concept/now-platform-encryption.dita/now-platform-encryption.html" target="_blank" rel="noopener noreferrer">Platform Encryption</a>.</div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getValue_String__table_ev2_flr_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 91. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7946">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7949">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7952">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7946 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7949 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7952 ">Name of a field for which to retrieve its value.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-getValue_String__table_fv2_flr_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 92. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7989">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e7992">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7989 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e7992 ">Value of the specified element. Returns null if the field is empty or the field does not exist. <div class="note"><span class="notetitle">Note:</span> Boolean values return as "0" and "1" string values instead of false and true.</div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example uses the <span class="keyword apiname">getValue()</span> method to obtain field values in two GlideRecords that are being compared.</p> <pre class="pre codeblock"><code>function() { var jobExists = true; var jobGr; while(jobExists){ jobGr = new GlideRecord("sys_trigger"); jobExists = jobGr.get("name", "BaselineAPI: Create Baseline Job"); } var baselineGr = new GlideRecord('pm_project_baseline'); baselineGr.get('baseline_name','Test Project Baseline'); baselineGr.query(); Assert.assertEquals(true, baselineGr.next()); var projectGr = new GlideRecord('pm_project'); projectGr.get(this._project); Assert.assertEquals(projectGr.getValue('cost'), baselineGr.getValue('cost')); Assert.assertEquals((projectGr.getValue('capex_cost')), baselineGr.getValue('capex_cost')); Assert.assertEquals((projectGr.getValue('opex_cost')), baselineGr.getValue('opex_cost')); Assert.assertEquals((projectGr.getValue('budget_cost')), baselineGr.getValue('budget_cost')); Assert.assertEquals((projectGr.getValue('value')), baselineGr.getValue('value')); Assert.assertEquals((projectGr.getValue('npv_value')), baselineGr.getValue('npv_value')); Assert.assertEquals((projectGr.getValue('score')), baselineGr.getValue('score')); }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">getValue()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordGetValue_String" title="Retrieves the string value of an underlying element in a field.">getValue()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-constructor" id="r_GlideRecord-GlideRecord_S"> <h2 class="title topictitle2" id="ariaid-title48">GlideRecord - GlideRecord(String tableName)</h2> <div class="body refbody"><p class="shortdesc">Creates an instance of the GlideRecord class for the specified table.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-GlideRecord_S__table_v1n_btj_3v" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 93. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8112">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8115">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8118">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8112 ">tableName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8115 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8118 ">Table to use.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident');</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-hasAttachments"> <h2 class="title topictitle2" id="ariaid-title49">GlideRecord - hasAttachments()</h2> <div class="body refbody"><p class="shortdesc">Determines if the current GlideRecord has any attachments.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-hasAttachments__table_dz4_fzp_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 94. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8207">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8210">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8213">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8207 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8210 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8213 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-hasAttachments__table_ez4_fzp_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 95. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8248">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8251">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8248 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8251 ">True if the current record has attachments, false otherwise.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks for attachments and creates a link if there are any.</p> <pre class="pre codeblock"><code>var attachment_link = ''; var rec = new GlideRecord('sc_req_item'); rec.addQuery('sys_id', current.request_item); rec.query(); if(rec.next()){ if(rec.hasAttachments()){ attachment_link = gs.getProperty('glide.servlet.uri') + rec.getLink(); } }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-hasNext"> <h2 class="title topictitle2" id="ariaid-title50">GlideRecord - hasNext()</h2> <div class="body refbody"><p class="shortdesc">Determines if there are any more records in the GlideRecord.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-hasNext__table_fn3_cnq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 96. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8341">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8344">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8347">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8341 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8344 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8347 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-hasNext__table_gn3_cnq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 97. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8382">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8385">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8382 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8385 ">True if there are more records in the query set, otherwise false.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to call different functions based on whether there are additional records in the current GlideRecord.</p> <pre class="pre codeblock"><code>if (now_GR.hasNext()) { dothis(); // found it, do it } else { dothat(); // didn't find it };</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-hasNext__section_qb3_y2s_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">hasNext()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordHasNext" title="Determines if there are any more records in the GlideRecord object.">hasNext()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-initialize"> <h2 class="title topictitle2" id="ariaid-title51">GlideRecord - initialize()</h2> <div class="body refbody"><p class="shortdesc">Creates an empty record within the current GlideRecord that is suitable for population before an insert.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-initialize__table_t1p_myw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 98. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8493">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8496">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8499">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8493 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8496 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8499 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-initialize__table_u1p_myw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 99. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8534">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8537">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8534 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8537 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example initializes a new record in the to_do table, creates a record, and then inserts it into the table.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('to_do'); now_GR.initialize(); now_GR.name = 'first to do item'; now_GR.description = 'learn about GlideRecord'; now_GR.insert();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-initialize__section_j1j_1fs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">initialize()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordInitialize" title="Creates an empty record suitable for population before an insert.">initialize()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-insert"> <h2 class="title topictitle2" id="ariaid-title52">GlideRecord - insert()</h2> <div class="body refbody"><p class="shortdesc">Inserts a new record with the field values that have been set for the current record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-insert__table_t3h_vyw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 100. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8645">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8648">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8651">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8645 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8648 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8651 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-insert__table_u3h_vyw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 101. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8686">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8689">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8686 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8689 ">The sys_id of the inserted record, or null if the record is not inserted.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example creates a new record in the to_do table, sets values for some record fields, and then inserts the record into the table.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('to_do'); now_GR.initialize(); now_GR.name = 'first to do item'; now_GR.description = 'learn about GlideRecord'; now_GR.insert();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-insert__section_dkx_cfs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">insert()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordInsert" title="Inserts a new record using the field values that have been set for the current record.">insert()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-insertWithReferences"> <h2 class="title topictitle2" id="ariaid-title53">GlideRecord - insertWithReferences()</h2> <div class="body refbody"><p class="shortdesc">Inserts a new record and also inserts or updates any related records with the provided information.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-insertWithReferences__table_scr_fzw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 102. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8797">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8800">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8803">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8797 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8800 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8803 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-insertWithReferences__table_tcr_fzw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 103. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8838">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8841">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8838 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8841 ">sys_id of the inserted record or null if the record was not inserted.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">If a reference value is not specified (as below), then a new user record is created with the provided first_name and last_name, and the caller_id value is set to this newly created sys_user record. The result is a new sys_user record with the provided first_name and last_name and a new incident record with the provided short_description and caller_id.</p> <pre class="pre codeblock"><code>var inc = new GlideRecord('incident'); inc.initialize(); inc.short_description = 'New incident 1'; inc.caller_id.first_name = 'John'; inc.caller_id.last_name = 'Doe'; inc.insertWithReferences();</code></pre> </div> <div class="example"> <p class="p">If a caller_id value is specified, then that caller_id is updated with the provided first_name and last_name. The result is a newly created incident record with values set for short_description and caller_id.</p> <pre class="pre codeblock"><code>var inc = new GlideRecord('incident'); inc.initialize(); inc.short_description = 'New incident 1'; inc.caller_id.setDisplayValue('David Loo'); inc.caller_id.first_name = 'John'; inc.caller_id.last_name = 'Doe'; inc.insertWithReferences();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-instanceOf_String"> <h2 class="title topictitle2" id="ariaid-title54">GlideRecord - instanceOf(String className)</h2> <div class="body refbody"><p class="shortdesc">Checks a table for the type\class of table.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-instanceOf_String__table_s5n_qnq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 104. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8940">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8943">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8946">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8940 ">className</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8943 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8946 ">Name of a type or class of record.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-instanceOf_String__table_t5n_qnq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 105. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8983">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e8986">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8983 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e8986 ">True if table is an instance of the specified class.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks if the passed in group/user is of the sys_user table/class type.</p> <pre class="pre codeblock"><code>function(groupOrUser, label, grantedBy) { var labelCheck; var labelRecord; if (typeof label === "string") { labelRecord = new GlideRecord('label'); labelRecord.addQuery('name', label); labelRecord.query(); labelRecord.next(); } else { labelRecord = label; } if (groupOrUser.instanceOf('sys_user')) { labelCheck = new GlideRecord('label_user_m2m'); labelCheck.addQuery('user', groupOrUser.sys_id); } else { labelCheck = new GlideRecord('label_group_m2m'); labelCheck.addQuery('group', groupOrUser.sys_id); } labelCheck.addQuery('label', labelRecord.sys_id); if (grantedBy !== "undefined") { labelCheck.addQuery('granted_by', grantedBy.sys_id); } labelCheck.query(); return labelCheck.hasNext(); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-isNewRecord"> <h2 class="title topictitle2" id="ariaid-title55">GlideRecord - isNewRecord()</h2> <div class="body refbody"><p class="shortdesc">Determines whether the current record has been inserted into the database.</p> <div class="section"> <p class="p">This method returns true only if the <span class="keyword apiname">newRecord()</span> method has been called. This method is useful for scripted ACL, and in the condition of UI actions, but should not be used in background scripts.</p> <div class="note"><span class="notetitle">Note:</span> This method returns true for any new record during a business rule, or if the <span class="keyword apiname">newRecord()</span> method is used to initialize a record with default values and a unique ID (sys_id). In all other cases, it returns false.</div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isNewRecord__table_vbn_g4q_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 106. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9086">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9089">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9092">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9086 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9089 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9092 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isNewRecord__table_wbn_g4q_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 107. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9127">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9130">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9127 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9130 ">Flag that indicates whether the current record is new (has not been inserted into the database.)<div class="p">Possible values:<ul class="ul" id="r_GlideRecord-isNewRecord__ul_cqj_2fx_z4b"><li class="li">true: Record is new.</li><li class="li">false: Record is not new.</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks if the new record has been inserted into the sys_user table.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("sys_user"); now_GR.newRecord(); now_GR.setValue("user_name", "John Smith"); gs.print("Is this a new record: " + now_GR.isNewRecord()); var now_GR2 = new GlideRecord("sys_user"); now_GR2.addQuery("user_name", "Abel Tutor"); now_GR2.query(); now_GR2.next(); gs.print("Is this a new record: " + now_GR2.isNewRecord());</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-isValid"> <h2 class="title topictitle2" id="ariaid-title56">GlideRecord - isValid()</h2> <div class="body refbody"><p class="shortdesc">Determines if the current GlideRecord table exists.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isValid__table_twy_x4q_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 108. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9230">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9233">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9236">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9230 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9233 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9236 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isValid__table_uwy_x4q_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 109. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9271">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9274">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9271 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9274 ">True if the table is exists (valid), otherwise false.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks if the Incident table exists.</p> <pre class="pre codeblock"><code>var testTable = new GlideRecord('incident'); gs.print(testTable.isValid());</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-isValid__section_ipl_hfs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">isValid()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordIsValid" title="Determines if the current table is valid or if the record was successfully retrieved.">isValid()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-isValidField_String"> <h2 class="title topictitle2" id="ariaid-title57">GlideRecord - isValidField(String fieldName)</h2> <div class="body refbody"><p class="shortdesc">Determines if the specified field is defined in the current GlideRecord table.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isValidField_String__table_hkx_vpq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 110. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9382">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9385">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9388">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9382 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9385 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9388 ">Name of a field to check.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isValidField_String__table_ikx_vpq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 111. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9425">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9428">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9425 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9428 ">True if the field is defined in the table, otherwise false.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks if the sys_class_name field exists in the cmds_software_instance table.</p> <pre class="pre codeblock"><code>var gobj = new GlideRecord('sys_db_object'); gobj.addQuery('name','cmdb_software_instance'); gobj.query(); if (!gobj.next()) { var si = new GlideRecord('cmdb_software_instance'); si.query(); var count = 0; while (si.next()) { if (!si.isValidField('sys_class_name')) { var ci = new GlideRecord('cmdb_ci'); ci.name = si.name; ci.setNewGuidValue(si.sys_id); ci.sys_class_name = 'cmdb_software_instance'; ci.insert(); count++; } } }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">isValidField()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordIsValidField" title="Determines if the specified field is defined in the current table.">isValidField()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-isValidRecord"> <h2 class="title topictitle2" id="ariaid-title58">GlideRecord - isValidRecord()</h2> <div class="body refbody"><p class="shortdesc">Determines if the current record is valid.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isValidRecord__table_ld5_3qq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 112. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9537">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9540">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9543">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9537 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9540 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9543 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-isValidRecord__table_md5_3qq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 113. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9578">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9581">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9578 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9581 ">Flag indicating whether the current record is valid.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-isValidRecord__ul_dqt_bxs_1nb"><li class="li">true: Record is valid.</li><li class="li">false: Past the end of the record set.</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks if the record identifier by the passed in sys_id is a valid record in the idea table.</p> <pre class="pre codeblock"><code>function(sysId) { this.log('Inside acceptIdea sysId = ' + sysId); var now_GR = new GlideRecord('idea'); now_GR.get(sysId); this.log('now_GR.isValidRecord() = ' + now_GR.isValidRecord()); if(now_GR.isValidRecord()) { now_GR.setValue('state', 2); this.log('Updating gliderecord'); this.log('gliderecord table name' + now_GR.getTableName()); now_GR.update(); } }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">isValidRecord()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordIsValidRecord" title="Determines if a record was actually returned by the query/get record operation.">isValidRecord()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-newRecord"> <h2 class="title topictitle2" id="ariaid-title59">GlideRecord - newRecord()</h2> <div class="body refbody"><p class="shortdesc">Creates a GlideRecord, sets the default values for the fields, and assigns a unique ID to the record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-newRecord__table_pzw_yzw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 114. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9699">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9702">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9705">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9699 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9702 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9705 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-newRecord__table_qzw_yzw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 115. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9740">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9743">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9740 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9743 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example checks if the new record has been inserted into the sys_user table.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord("sys_user"); now_GR.newRecord(); now_GR.setValue("user_name", "John Smith"); gs.print("Is this a new record: " + now_GR.isNewRecord()); var now_GR2 = new GlideRecord("sys_user"); now_GR2.addQuery("user_name", "Abel Tutor"); now_GR2.query(); now_GR2.next(); gs.print("Is this a new record: " + now_GR2.isNewRecord());</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">newRecord()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordNewRecord" title="Creates a new GlideRecord record, sets the default values for the fields, and assigns a unique ID to the record.">newRecord()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-next"> <h2 class="title topictitle2" id="ariaid-title60">GlideRecord - next()</h2> <div class="body refbody"><p class="shortdesc">Moves to the next record in the GlideRecord.</p> <div class="section"> <p class="p">Use this method to iterate through the records returned by a GlideRecord query.</p> <div class="note"><span class="notetitle">Note:</span> This method fails if there is a field in the table called "next". If that is the case, use the method <a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-_next" title="Moves to the next record in the GlideRecord. Provides the same functionality as next(), intended to be used in cases where the GlideRecord has a column named next.">_next()</a>.</div> <div class="note"><span class="notetitle">Note:</span> The <code class="ph codeph">if(myObj.next())</code> construct only processes the first record returned.</div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-next__table_s2n_yqq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 116. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9873">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9876">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9879">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9873 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9876 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9879 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-next__table_t2n_yqq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 117. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9914">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e9917">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9914 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e9917 ">Flag that indicates if there is a "next" record in the GlideRecord. <div class="p">Valid values:<ul class="ul" id="r_GlideRecord-next__ul_anq_km4_s3b"><li class="li">true: Move to the next record was successful.</li><li class="li">false: No more records in the result set.</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to iterate through the Incident table using the <span class="keyword apiname">next()</span> method.</p> <pre class="pre codeblock"><code>var rec = new GlideRecord('incident'); rec.query(); while (rec.next()) { gs.print(rec.number + ' exists'); }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-next__section_by3_qfs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">next()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordNext" title="Moves to the next record in the GlideRecord object.">next()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-_next"> <h2 class="title topictitle2" id="ariaid-title61">GlideRecord - _next()</h2> <div class="body refbody"><p class="shortdesc">Moves to the next record in the GlideRecord. Provides the same functionality as <span class="keyword apiname">next()</span>, intended to be used in cases where the GlideRecord has a column named next.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-_next__table_nwr_3rq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 118. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10041">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10044">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10047">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10041 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10044 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10047 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-_next__table_owr_3rq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 119. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10082">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10085">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10082 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10085 ">True if there are more records in the query set.</td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var rec = new GlideRecord('sys_template'); rec.query(); while (rec._next()) { gs.print(rec.number + ' exists'); }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-_next__section_ucp_vcs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">_next()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#SGR-_next" title="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.">_next()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-operation"> <h2 class="title topictitle2" id="ariaid-title62">GlideRecord - operation()</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Determines if an operation is insert, update, or delete.</span></p> <div class="section"> <p class="p">Knowing the operation enables using <span class="keyword apiname">current.operation()</span> to make a generic business rule which can handle each operation uniquely.</p> <p class="p">For information on using the global variable <span class="keyword apiname">current</span>, refer to <a class="xref" href="script/business-rules/concept/c_BusinessRules.html#c_UsingPredefinedGlobalVariables" target="_blank" rel="noopener noreferrer">Global variables in business rules</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-operation__table_a3h_wrq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 120. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10211">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10214">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10217">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10211 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10214 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10217 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-operation__gr-operation-returns" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 121. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10252">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10255">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10252 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10255 ">The current operation.<div class="p">Possible values:<ul class="ul" id="r_GlideRecord-operation__ul_bnp_xs3_bpb"><li class="li">delete</li><li class="li">insert</li><li class="li">update</li></ul> </div> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-operation__example_uf5_2qj_bpb"> <p class="p">The following example shows how to use this method in a business rule. The <span class="keyword apiname">operation()</span> method detects which operation triggered an event and performs a different action depending for update and insert operations.</p> <pre class="pre codeblock"><code>if(current.operation() == "update") { current.updates ++; } if(current.operation() == "insert") { current.updates = 0; }</code></pre> </div> <div class="example" id="r_GlideRecord-operation__example_wdf_c4t_1nb"> <p class="p">This example shows how to use the <span class="keyword apiname">operation()</span> method to pass the operation value into the <span class="keyword apiname">startFlow()</span> method.</p> <pre class="pre codeblock"><code>function createNewTransferOrder() { var toGr = new GlideRecord("alm_transfer_order"); toGr.initialize(); // From Stockroom - Southern California Warehouse toGr.setValue('from_stockroom', fromStockroomSysId); // To Stockroom - San Diego North - Pickup/Dropoff toGr.setValue('to_stockroom', toStockroomSysId); var transferOrder = toGr.insert(); if(toGr.get(transferOrder)){ // Start Transfer Order Workflow var wf = new Workflow(); var context = wf.startFlow(toWorkflowSysId, toGr, toGr.operation(),{}); createNewTransferOrderLine(transferOrder); } }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">operation()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordOperation" title="Determines if an operation is insert, update, or delete.">operation()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-orderBy_String"> <h2 class="title topictitle2" id="ariaid-title63">GlideRecord - orderBy(String fieldName)</h2> <div class="body refbody"><p class="shortdesc">Specifies a field name to use to order the query set. To order by multiple fields, call this method multiple times with different field values.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-orderBy_String__table_rr5_fsq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 122. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10395">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10398">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10401">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10395 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10398 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10401 ">Field on which to order the query set.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-orderBy_String__table_sr5_fsq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 123. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10438">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10441">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10438 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10441 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to order the query set by "order" and then by "number".</p> <pre class="pre codeblock"><code>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(); var len = child.getRowCount().toString().length; var seq = 0; while (child.next()) { count += UpdateProjectTaskWBS(child, 1, ++seq, len, ''); } gs.addInfoMessage(count + ' Project Tasks updated'); }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-orderBy_String__section_slw_vfs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">orderBy()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordOrderBy_String" title="Specifies an orderBy column.">orderBy()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-orderByDesc_String"> <h2 class="title topictitle2" id="ariaid-title64">GlideRecord - orderByDesc(String, fieldName)</h2> <div class="body refbody"><p class="shortdesc">Specifies the field to use to order the query set in descending order.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-orderByDesc_String__table_yht_ysq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 124. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10549">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10552">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10555">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10549 ">fieldName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10552 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10555 ">Name of field to use to order the query results in descending order.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-orderByDesc_String__table_zht_ysq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 125. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10592">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10595">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10592 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10595 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-orderByDesc_String__example_rkx_cqt_1nb"> <p class="p">This example shows how to order the query set in ascending or descending order.</p> <pre class="pre codeblock"><code>function(fiscalType, orderByDesc) { var now_GR = new GlideRecord('fiscal_period'); now_GR.addQuery('fiscal_type', fiscalType); if (orderByDesc) { now_GR.orderByDesc('fiscal_start_date_time'); } else { now_GR.orderBy('fiscal_start_date_time'); } now_GR.setLimit(1); now_GR.query(); now_GR.next(); return now_GR.sys_id; }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">orderByDesc()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordOrderByDesc_String" title="Specifies a descending orderBy column.">orderByDesc()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-query_Object_Object"> <h2 class="title topictitle2" id="ariaid-title65">GlideRecord - query(String field, String value)</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Runs a query against the table based on the filters specified in the query methods such as <span class="keyword apiname">addQuery()</span> and <span class="keyword apiname">addEncodedQuery()</span>.</span></p> <div class="section"> <p class="p">This method queries the GlideRecord table as well as any references of the table. For more information, see <a class="xref" href="../../../../../script/server-scripting/concept/c_UsingGlideRecordToQueryTables.html" title="Using methods in the GlideRecord API, you can return all records from a table, return records from a table that satisfy specific conditions, or return records that include a string from a single table or from multiple tables in a text index group.">Querying tables in script</a>.</p> <div class="p"><div class="note"><span class="notetitle">Note:</span> This method fails if there is a field in the table called "query". If that is the case, use the method <a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-_query_Object_Object" title="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.">_query()</a>. To run queries in a domain-separated instance, use the method <a class="xref" href="c_GlideRecordAPI.html#r_GlideRecord-queryNoDomain_Object_Object" title="Used in domain-separated instances. Similar to query(), runs the query against the table based on the filters specified by addQuery() and addEncodedQuery(), but ignores domains.">queryNoDomain()</a>.</div> </div> <p class="p"><span class="ph">See the <a class="xref" href="https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_scripting_in_servicenow/app_store_learnv2_scripting_utah_server_side_scripting/app_store_learnv2_scripting_utah_gliderecord" target="_blank" rel="noopener noreferrer">GlideRecord</a> article for details on building and running queries.</span></p> <div class="p">See also:<ul class="ul" id="r_GlideRecord-query_Object_Object__ul_qcl_14d_lpb"><li class="li"><a class="xref" href="../../GlideAggregate/concept/c_GlideAggregateAPI.html" title="GlideAggregate enables creating database aggregation queries.">GlideAggregate</a></li><li class="li" id="r_GlideRecord-query_Object_Object__gr-api-global-link2gquery-api"><a class="xref" href="../../GlideQuery/concept/GlideQueryGlobalAPI.html" title="The GlideQuery API is an alternative to GlideRecord to perform CRUD operations on record data from server-side scripts.">GlideQuery()</a></li><li class="li"><a class="xref" href="../../GlideQueryCondition/concept/c_GlideQueryConditionAPI.html" title="The GlideQueryCondition API provides additional AND or OR conditions that can be added to the current condition, allowing you to build complex queries.">GlideQueryCondition</a></li></ul> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-query_Object_Object__id_g13_kwd_lpb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 126. </span>Parameters</span></caption><colgroup><col style="width:20%" /><col style="width:20%" /><col style="width:60%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10803">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10806">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10809">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10803 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10806 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10809 ">Optional - must also specify a value parameter. Name of the field to search for the value specified in the value parameter.<div class="p" id="r_GlideRecord-query_Object_Object__gr-query-note-parms"> <div class="note"><span class="notetitle">Note:</span> 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.</div> </div> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10803 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10806 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10809 ">Optional - must also specify a field parameter. Value to search for in the specified field parameter.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-query_Object_Object__table_qsd_ntq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 127. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10864">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e10867">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10864 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e10867 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-query_Object_Object__example_qfw_lwd_lpb"> <p class="p">The following example shows how to scan the System Dictionary [sys_dictionary] for tables with a query field.</p> <pre class="pre codeblock"><code>var tableArr = []; var now_GR = new GlideRecord('sys_dictionary'); now_GR.addQuery('element', 'query'); now_GR.setLimit(6); now_GR.query(); while(now_GR.next()){ tableArr.push(now_GR.name.getValue()); }; gs.info('The following tables have a field column called "query":'); for (i = 0; i < tableArr.length; i++) { gs.info(tableArr[i]); };</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>The following tables have a field column called "query": cmdb_convert_bulk_services cmdb_multisource_query_status cmdb_qb_result_base cmdb_qb_table_mapping discovery_probes_cim_query kb_feedback</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-query_Object_Object__section_xt2_zfs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">query()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordQuery_Object_Object" title="Runs a query against the table based on the filters specified in the query methods such as addQuery() and addEncodedQuery().">query()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-_query_Object_Object"> <h2 class="title topictitle2" id="ariaid-title66">GlideRecord - _query(String field, String value)</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Runs a query against the table based on the filters specified in the query methods such as <span class="keyword apiname">addQuery()</span> and <span class="keyword apiname">addEncodedQuery()</span>.</span> <span class="ph">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.</span></p> <div class="section"> <p class="p">This method queries the GlideRecord table as well as any references of the table. For more information, see <a class="xref" href="../../../../../script/server-scripting/concept/c_UsingGlideRecordToQueryTables.html" title="Using methods in the GlideRecord API, you can return all records from a table, return records from a table that satisfy specific conditions, or return records that include a string from a single table or from multiple tables in a text index group.">Querying tables in script</a>.</p> <p class="p"><span class="ph">See the <a class="xref" href="https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_scripting_in_servicenow/app_store_learnv2_scripting_utah_server_side_scripting/app_store_learnv2_scripting_utah_gliderecord" target="_blank" rel="noopener noreferrer">GlideRecord</a> article for details on building and running queries.</span></p> <div class="p">See also:<ul class="ul" id="r_GlideRecord-_query_Object_Object__ul_qcl_14d_lpb"><li class="li"><a class="xref" href="../../GlideAggregate/concept/c_GlideAggregateAPI.html" title="GlideAggregate enables creating database aggregation queries.">GlideAggregate</a></li><li class="li" id="r_GlideRecord-_query_Object_Object__gr-api-global-link2gquery-api"><a class="xref" href="../../GlideQuery/concept/GlideQueryGlobalAPI.html" title="The GlideQuery API is an alternative to GlideRecord to perform CRUD operations on record data from server-side scripts.">GlideQuery()</a></li><li class="li"><a class="xref" href="../../GlideQueryCondition/concept/c_GlideQueryConditionAPI.html" title="The GlideQueryCondition API provides additional AND or OR conditions that can be added to the current condition, allowing you to build complex queries.">GlideQueryCondition</a></li></ul> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-_query_Object_Object__id_z1c_ptd_lpb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 128. </span>Parameters</span></caption><colgroup><col style="width:20%" /><col style="width:20%" /><col style="width:60%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11055">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11058">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11061">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11055 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11058 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11061 ">Optional - must also specify a value parameter. Name of the field to search for the value specified in the value parameter.<div class="p" id="r_GlideRecord-_query_Object_Object__gr-query-note-parms"> <div class="note"><span class="notetitle">Note:</span> 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.</div> </div> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11055 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11058 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11061 ">Optional - must also specify a field parameter. Value to search for in the specified field parameter.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-_query_Object_Object__table_dvc_s5q_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 129. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11115">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11118">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11115 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11118 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-_query_Object_Object__example_m4b_kmk_lpb"> <p class="p">The following example shows how query the Knowledge Feedback [kb_feedback] table and list KB articles with comments that include Excel.</p> <pre class="pre codeblock"><code>var rec = new GlideRecord('kb_feedback'); rec.addQuery('comments', 'CONTAINS', 'Excel'); rec._query(); while (rec.next()) { gs.info(rec.getDisplayValue('article') + " comment: " + rec.getValue('comments')); }</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>KB0000005 comment: Can you please add the version of Excel this applies to? All? KB0000005 comment: Does this work for all Excel versions? OSX and Windows alike?</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-_query_Object_Object__section_u4j_xcs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">_query()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#SGR-_query_O_O" title="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.">_query()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-queryNoDomain_Object_Object"> <h2 class="title topictitle2" id="ariaid-title67">GlideRecord - queryNoDomain(String field, String value)</h2> <div class="body refbody"><p class="shortdesc">Used in domain-separated instances. Similar to <span class="keyword apiname">query()</span>, runs the query against the table based on the filters specified by <span class="keyword apiname">addQuery()</span> and <span class="keyword apiname">addEncodedQuery()</span>, but ignores domains.</p> <div class="section"> <p class="p">This method queries the GlideRecord table as well as any references of the table. For more information, see <a class="xref" href="../../../../../script/server-scripting/concept/c_UsingGlideRecordToQueryTables.html" title="Using methods in the GlideRecord API, you can return all records from a table, return records from a table that satisfy specific conditions, or return records that include a string from a single table or from multiple tables in a text index group.">Querying tables in script</a>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-queryNoDomain_Object_Object__id_n1d_1jk_lpb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 130. </span>Parameters</span></caption><colgroup><col style="width:20%" /><col style="width:20%" /><col style="width:60%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11248">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11251">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11254">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11248 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11251 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11254 ">Optional - must also specify a value parameter. Name of the field to search for the value specified in the value parameter.<div class="p" id="r_GlideRecord-queryNoDomain_Object_Object__gr-query-note-parms"> <div class="note"><span class="notetitle">Note:</span> 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.</div> </div> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11248 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11251 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11254 ">Optional - must also specify a field parameter. Value to search for in the specified field parameter.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-queryNoDomain_Object_Object__table_w2k_25q_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 131. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11308">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11311">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11308 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11311 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to query the incident table for all domains.</p> <pre class="pre codeblock"><code>var rec = new GlideRecord('incident'); rec.queryNoDomain(); while (rec.next()) { gs.print(rec.number + ' exists'); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-restoreLocation_Boolean"> <h2 class="title topictitle2" id="ariaid-title68">GlideRecord - restoreLocation()</h2> <div class="body refbody"><p class="shortdesc">Sets the current record to be the record that was saved with <span class="keyword apiname">saveLocation()</span>. If <span class="keyword apiname">saveLocation()</span> has not been called, the current record is set to the first record of the GlideRecord.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-restoreLocation_Boolean__table_vgz_jvq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 132. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11406">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11409">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11412">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11406 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11409 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11412 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-restoreLocation_Boolean__table_wgz_jvq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 133. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11447">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11450">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11447 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11450 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how save the current record location, move to the next record, and then return back to the saved location.</p> <pre class="pre codeblock"><code>function() { var now_GR = new GlideRecord("incident"); now_GR.query(); now_GR.next(); var firstID = now_GR.getValue("sys_id"); now_GR.next(); var restoreID = now_GR.getValue("sys_id"); now_GR.saveLocation(); now_GR.next(); var lastID = now_GR.getValue("sys_id"); now_GR.restoreLocation(); now_GR.next(); var thisID = now_GR.getValue("sys_id"); var progress = "first id=" + firstID + "\n\t last id=" + lastID + "\n\t saved id=" + restoreID + "\n\t restored id=" + thisID; gs.print("Progress:\n\t" + progress); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-saveLocation"> <h2 class="title topictitle2" id="ariaid-title69">GlideRecord - saveLocation()</h2> <div class="body refbody"><p class="shortdesc">Saves the current row number so you can return to this location using the <span class="keyword apiname">restoreLocation()</span> method.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-saveLocation__table_xpb_zvq_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 134. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11541">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11544">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11547">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11541 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11544 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11547 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-saveLocation__table_ypb_zvq_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 135. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11582">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11585">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11582 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11585 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-saveLocation__example_exm_kwt_1nb"> <p class="p">This example shows how save the current record location, move to the next record, and then return back to the saved location.</p> <pre class="pre codeblock"><code>function() { var now_GR = new GlideRecord("incident"); now_GR.query(); now_GR.next(); var firstID = now_GR.getValue("sys_id"); now_GR.next(); var restoreID = now_GR.getValue("sys_id"); now_GR.saveLocation(); now_GR.next(); var lastID = now_GR.getValue("sys_id"); now_GR.restoreLocation(); now_GR.next(); var thisID = now_GR.getValue("sys_id"); var progress = "first id=" + firstID + "\n\t last id=" + lastID + "\n\t saved id=" + restoreID + "\n\t restored id=" + thisID; gs.print("Progress:\n\t" + progress); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setAbortAction_Boolean"> <h2 class="title topictitle2" id="ariaid-title70">GlideRecord - setAbortAction(Boolean b)</h2> <div class="body refbody"><p class="shortdesc">Sets a flag to indicate if the next database action (insert, update, delete) is to be aborted.</p> <div class="section"> <p class="p"> Use in an <code class="ph codeph">onBefore</code> business rule to prevent the database action from being done. The business rule continues to run after <span class="keyword apiname">setAbortAction()</span> is called. Calling <span class="keyword apiname">setAbortAction()</span> does not stop subsequent business rules from executing. Calling this method only prevents the database action from occurring.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setAbortAction_Boolean__table_dch_kgw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 136. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11686">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11689">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11692">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11686 ">b</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11689 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11692 ">True to abort next action, or false to allow the next action.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setAbortAction_Boolean__table_ech_kgw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 137. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11729">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11732">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11729 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11732 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>if ((!current.u_date1.nil()) && (!current.u_date2.nil())) { var start = current.u_date1.getGlideObject().getNumericValue(); var end = current.u_date2.getGlideObject().getNumericValue(); if (start > end) { gs.addInfoMessage('start must be before end'); current.u_date1.setError('start must be before end'); current.setAbortAction(true); } }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-setAbortAction_Boolean__section_qbn_bgs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">setAbortAction()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordSetAbortAction_Boolean" title="Sets a flag to indicate if the next database action (insert, update, delete) is to be aborted. This is often used in business rules.">setAbortAction()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setDisplayValue_String_Object"> <h2 class="title topictitle2" id="ariaid-title71">GlideRecord - setDisplayValue(String name, Object value)</h2> <div class="body refbody"><p class="shortdesc">Sets the specified field to the specified display value.</p> <div class="section"> <p class="p">For a reference field this is the display value for the table. For a date/time this is the time in the caller's current timezone.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setDisplayValue_String_Object__table_ijf_wgw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 138. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11839">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11842">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11845">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11839 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11842 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11845 ">Name of the field for which to set the display value.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11839 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11842 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11845 ">Display value for the specified field.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setDisplayValue_String_Object__table_jjf_wgw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 139. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11894">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11897">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11894 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11897 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); now_GR.get('46f09e75a9fe198100f4ffd8d366d17b'); now_GR.setDisplayValue('opened_at','2011-02-13 4:30:00'); now_GR.update();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setForceUpdate_Boolean"> <h2 class="title topictitle2" id="ariaid-title72">GlideRecord - setForceUpdate(Boolean force)</h2> <div class="body refbody"><p class="shortdesc">Updates the record even if fields have not changed.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setForceUpdate_Boolean__table_eds_lhw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 140. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11983">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11986">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e11989">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11983 ">force</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11986 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e11989 ">True to update even if fields have not changed, otherwise false.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setForceUpdate_Boolean__table_fds_lhw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 141. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12026">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12029">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12026 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12029 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-setForceUpdate_Boolean__example_svk_mxt_1nb"> <p class="p">This example shows how to force a record in the itfm_cost_model table to update even without changes.</p> <pre class="pre codeblock"><code>function() { gs.log("Update Script: Upgrade_cost_model_data.js started"); var now_GR = new GlideRecord("itfm_cost_model"); now_GR.initialize(); now_GR.addNullQuery("source_table"); now_GR.query(); while (now_GR.next()) { now_GR.setForceUpdate(true); var sourceTable = getSourceTable(now_GR.getValue('clone_from')); if(sourceTable){ now_GR.setValue("source_table", sourceTable); now_GR.setWorkflow(false); now_GR.update(); } } }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setLimit_Number"> <h2 class="title topictitle2" id="ariaid-title73">GlideRecord - setLimit(Number limit)</h2> <div class="body refbody"><p class="shortdesc">Sets the maximum number of records to return in the GlideRecord from a query.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setLimit_Number__table_pcb_whw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 142. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12117">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12120">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12123">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12117 ">limit</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12120 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12123 ">Limit for records to fetch.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setLimit_Number__table_qcb_whw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 143. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12160">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12163">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12160 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12163 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example sets the number of records returned in the query to a maximum of ten.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); now_GR.orderByDesc('sys_created_on'); now_GR.setLimit(10); now_GR.query();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-setLimit_Number__section_vrk_dgs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">setLimit()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordSetLimit_Number" title="Sets the limit for number of records are fetched by the GlideRecord query.">setLimit()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setLocation_Number"> <h2 class="title topictitle2" id="ariaid-title74">GlideRecord - setLocation(Number rowNumber)</h2> <div class="body refbody"><p class="shortdesc">Sets the current row location to the specified value.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setLocation_Number__table_tjd_j3w_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 144. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12271">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12274">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12277">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12271 ">rowNumber</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12274 ">Number</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12277 ">Row number to set as the current row.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setLocation_Number__table_ujd_j3w_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 145. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12314">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12317">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12314 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12317 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to set the record position in the Incident table</p> <pre class="pre codeblock"><code>verifySetLocation : function() { var now_GR = new GlideRecord("incident"); now_GR.query(); var recordIDs = new Array(); while(now_GR.next()) { recordIDs.push(now_GR.getValue("sys_id")); } for (var ix = recordIDs.length - 1; ix >= 0; ix--) { now_GR.setLocation(ix); Assert.assertEquals(recordIDs[ix], now_GR.getValue("sys_id"), "The entry retrieved for the index " + ix + " is not valid"); } }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setNewGuid"> <h2 class="title topictitle2" id="ariaid-title75">GlideRecord - setNewGuid()</h2> <div class="body refbody"><p class="shortdesc">Generates a new GUID and sets it as the unique ID (sys_id) for the current record.</p> <div class="section"> <p class="p">This function applies only to new records. You cannot change the GUID for an existing record.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setNewGuid__table_mjn_r3w_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 146. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12408">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12411">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12414">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12408 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12411 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12414 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setNewGuid__table_njn_r3w_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 147. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12449">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12452">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12449 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12452 ">Sys_id of the current record.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example creates a new task record and stores the ID in the task_rel_task table.</p> <pre class="pre codeblock"><code>var task = new GlideRecord ('task'); var tsk_id = task.setNewGuid(); task.description = "Request: " + current.request.number; task.description = task.description + "\n" + "Requested by: " + current.request.u_requested_by.name; task.description = task.description + "\n" + "Requested for: " + current.request.u_requested_for.name; task.description = task.description + "\n" + "Item: " + current.cat_item.name; var now_GR = new GlideRecord ('task_rel_task'); //link the incident to the request now_GR.parent = current.request; now_GR.child = tsk_id; now_GR.insert();</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setNewGuidValue_String"> <h2 class="title topictitle2" id="ariaid-title76">GlideRecord - setNewGuidValue (String guid)</h2> <div class="body refbody"><p class="shortdesc">Generates a new GUID and sets it as the unique ID for the current record, when inserting a new record.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setNewGuidValue_String__table_qgt_1jw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 148. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12542">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12545">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12548">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12542 ">guid</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12545 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12548 ">Value for the new GUID.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setNewGuidValue_String__table_rgt_1jw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 149. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12585">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12588">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12585 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12588 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example generates a new GUID and sets it as the unique ID for the newly created cmdb_software_instance record.</p> <pre class="pre codeblock"><code>var gobj = new GlideRecord('sys_db_object'); gobj.addQuery('name','cmdb_software_instance'); gobj.query(); if (!gobj.next()) { var si = new GlideRecord('cmdb_software_instance'); si.query(); var count = 0; while (si.next()) { if (!si.isValidField('sys_class_name')) { var ci = new GlideRecord('cmdb_ci'); ci.name = si.name; ci.setNewGuidValue(si.sys_id); ci.sys_class_name = 'cmdb_software_instance'; ci.insert(); count++; } }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">setNewGuidValue()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordSetNewGuidValue_String" title="Sets the sys_id value for the current record.">setNewGuidValue()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setQueryReferences_Boolean"> <h2 class="title topictitle2" id="ariaid-title77">GlideRecord - setQueryReferences(Boolean queryReferences)</h2> <div class="body refbody"><p class="shortdesc">Enables or disables using the reference field's display name when querying a reference field.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setQueryReferences_Boolean__table_zyr_ljw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 150. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12695">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12698">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12701">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12695 ">queryReferences</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12698 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12701 ">Flag indicating what time of data to generate.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-setQueryReferences_Boolean__ul_mts_315_1nb"><li class="li">true: Generate a string of display names.</li><li class="li">false: Generate a string of sys_ids.</li></ul> </div> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setQueryReferences_Boolean__table_azr_ljw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 151. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12748">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12751">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12748 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12751 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>var grByName = new GlideRecord(this.TEST_TABLE); grByName.addQuery("caller_id", userDisplayName); grByName.setQueryReferences(true); grByName.query(); if (grByName.hasNext()) { while(grByName.next()) { gs.print("Incident caller_id=" + grByName.caller_id); } } else { gs.print("NO RESULTS"); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setUseEngines_Boolean"> <h2 class="title topictitle2" id="ariaid-title78">GlideRecord - setUseEngines(Boolean e)</h2> <div class="body refbody"><p class="shortdesc">Disables or enables the running of any engines (approval rules / assignment rules).</p> <div class="section"> <div class="p"><div class="note warning"><span class="warningtitle">Warning:</span> Disabling the running of engines can have a significant impact on your <span class="ph">ServiceNow®</span> instance and how it operates. Ensure that you thoroughly test this change before deploying it to production.</div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setUseEngines_Boolean__table_gdy_vjw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 152. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12845">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12848">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12851">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12845 ">e</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12848 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12851 ">Flag that indicates whether to enable or disable the running of any engines.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-setUseEngines_Boolean__ul_rb1_bwx_zqb"><li class="li">true: Enable engines</li><li class="li">false: Disable engines</li></ul> </div> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setUseEngines_Boolean__table_hdy_vjw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 153. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12898">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e12901">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12898 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e12901 "> </td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example shows how to disable engines and business rules before executing a query.</p> <pre class="pre codeblock"><code>function auditOAuthInboundRequestsUsage(){ var now_GR = new GlideRecord("oauth_credential"); var oauthClient = now_GR.addJoinQuery("oauth_entity", "peer", "sys_id"); now_GR.addQuery("type", "access_token"); now_GR.addQuery("expires", ">", nowDateTime()); now_GR.addNullQuery("oauth_requestor_profile"); oauthClient.addCondition("active", "true"); oauthClient.addCondition("type", "client"); now_GR.setUseEngines(false); now_GR.setWorkflow(false); now_GR.query(); return now_GR.hasNext(); }</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setValue_String_Object"> <h2 class="title topictitle2" id="ariaid-title79">GlideRecord - setValue(String name, Object value)</h2> <div class="body refbody"><p class="shortdesc">Sets the specified field to the specified value.</p> <div class="section"> <p class="p">Normally a script would do a direct assignment, for example, <code class="ph codeph">now_GR.category = value</code>. However, if in a script the element name is a variable, then you can use <code class="ph codeph">now_GR.setValue(elementName, value)</code>. When setting a value, ensure the data type of the field matches the data type of the value you enter.</p> <div class="p">If the value parameter is null, the record is not updated, and an error is not thrown.<div class="note"><span class="notetitle">Note:</span> This method cannot be used on journal fields, use <a class="xref" href="../../GlideElement_global/concept/c_GlideElementAPI.html" title="The GlideElement API provides a number of convenient script methods for dealing with fields and their values. GlideElement methods are available for the fields of the current GlideRecord.">GlideElement.setJournalEntry()</a> instead.</div> </div> <div class="p"><div class="note"><span class="notetitle">Note:</span> If the <span class="ph">Column Level Encryption</span> Enterprise plugin is enabled and the instance has access to the key, this method can insert encrypted data into encrypted fields. If the instance does not have access to the key, this method returns an error. For more information, see <a class="xref" href="../administer/now-platform-encryption/concept/now-platform-encryption.dita/now-platform-encryption.html" target="_blank" rel="noopener noreferrer">Platform Encryption</a>.</div> </div> <div class="p"> <dl class="dl"> <dt class="dt dlterm">Not for authentication with password2 fields</dt> <dd class="dd">The <span class="keyword apiname">setValue()</span> 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.<p class="p">For password2 authentication, use the <span class="keyword apiname">setDisplayValue()</span> method instead.</p> <div class="p">See also:<ul class="ul" id="r_GlideRecord-setValue_String_Object__ul_m1z_5js_12c"><li class="li"><a class="xref" href="../administer/key-management-framework/concept/password2-3des-deprecation.dita/password2-3des-deprecation.html" target="_blank" rel="noopener noreferrer">Deprecate GlideEncrypter usage of 3DES for password2 fields</a></li><li class="li"> <a class="xref" href="https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1320986" target="_blank" rel="noopener noreferrer">Alternatives to GlideEncrypter usage in knowledge base article KB1320986</a></li><li class="li"><a class="xref" href="../administer/key-management-framework/concept/password-2way-encrypted-fields.dita/password-2way-encrypted-fields.html" target="_blank" rel="noopener noreferrer">Password2 encryption with the Key Management Framework (KMF)</a></li></ul> </div> </dd> </dl> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setValue_String_Object__table_yps_2kw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 154. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13070">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13073">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13076">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13070 ">name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13073 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13076 ">Name of the field whose value you want to set.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13070 ">value</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13073 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13076 ">Value to set in the specified field.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setValue_String_Object__table_zps_2kw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 155. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13126">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13129">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13126 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13129 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-setValue_String_Object__example_x2g_m25_1nb"> <p class="p">This example shows how to set the value of the state field in the planned_task table.</p> <pre class="pre codeblock"><code>function() { var topTask = new GlideRecord('planned_task'); topTask.setValue('state', -5); var childTask = new GlideRecord('planned_task'); childTask.setValue('state', -5); var s = new PlannedTaskStateManagement(childTask, topTask); var state = s.manageStateChange(false); Assert.assertEquals("-5", state); }</code></pre> </div> <div class="section scoped-equivalent"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">setValue()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordSetValue_String_Object" title="Sets the value of the field with the specified name to the specified value.">setValue()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-setWorkFlow_Boolean"> <h2 class="title topictitle2" id="ariaid-title80">GlideRecord - setWorkflow(Boolean e)</h2> <div class="body refbody"><p class="shortdesc">Enables or disables the running of business rules that might normally be triggered by subsequent actions. If the <span class="keyword parmname">e</span> parameter is set to false, an insert/update will not be audited. Auditing only happens when the parameter is set to true for a GlideRecord operation.</p> <div class="section"> <div class="note"><span class="notetitle">Note:</span> The <span class="keyword apiname">setWorkflow()</span> method is ignored when subsequently using either the <span class="keyword apiname">deleteProblem()</span> or <span class="keyword apiname">deleteMultiple()</span> methods to cascade delete.</div> <div class="p"><div class="note warning"><span class="warningtitle">Warning:</span> Disabling the running of business rules can have a significant impact on your <span class="ph">ServiceNow®</span> instance and how it operates. Ensure that you thoroughly test this change before deploying it to production.</div> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setWorkFlow_Boolean__table_xdz_skw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 156. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13260">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13263">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13266">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13260 ">e</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13263 ">Boolean</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13266 ">Flag that indicates whether to enable or disable the running of business rules.<div class="p">Valid values:<ul class="ul" id="r_GlideRecord-setWorkFlow_Boolean__ul_rb1_bwx_zqb"><li class="li">true: Enable business rules</li><li class="li">false: Disable business rules</li></ul> </div> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-setWorkFlow_Boolean__table_ydz_skw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 157. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13313">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13316">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13313 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13316 "> </td></tr></tbody></table> </div> </div> <div class="example"> <pre class="pre codeblock"><code>doit('name1','name2'); function doit(username1,username2) { var usr1 = new GlideRecord('sys_user'); var usr2 = new GlideRecord('sys_user'); var num = 0; if (usr1.get('user_name',username1) && usr2.get('user_name',username2)) { var ref; var dict = new GlideRecord('sys_dictionary'); dict.addQuery('reference','sys_user'); dict.addQuery('internal_type','reference'); dict.query(); while (dict.next()) { num = 0; ref = new GlideRecord(dict.name.toString()); ref.addQuery(dict.element,usr1.sys_id); ref.query(); while (ref.next()) { ref.setValue(dict.element.toString(),usr2.sys_id); ref.setWorkflow(false); ref.update(); num++; } if (num > 0) { gs.print(dict.element + ' changed from ' + usr1.user_name + ' to ' + usr2.user_name + ' in ' + num + ' ' + dict.name + ' records'); } } } }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-setWorkFlow_Boolean__section_hhf_4gs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">setWorkflow()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordSetWorkflow_Boolean" title="Enables or disables the running of business rules, script engines, and audit.">setWorkflow()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-update_Object"> <h2 class="title topictitle2" id="ariaid-title81">GlideRecord - update(Object reason)</h2> <div class="body refbody"><p class="shortdesc">Updates the GlideRecord with any changes that have been made. If the record does not exist, it is inserted.</p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-update_Object__table_ovg_wlw_dt" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 158. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13420">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13423">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13426">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13420 ">reason</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13423 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13426 ">Optional. Reason for the update. The reason appears in the audit record.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-update_Object__table_pvg_wlw_dt" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 159. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13463">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13466">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13463 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13466 ">The sys_id of the new or update record. Returns null if the update fails.</td></tr></tbody></table> </div> </div> <div class="example"> <p class="p">This example updates a record in the task_ci table.</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('task_ci'); now_GR.addQuery(); now_GR.query(); var count = now_GR.getRowCount(); if (count > 0) { var allocation = parseInt(10000 / count) / 100; while (now_GR.next()) { now_GR.u_allocation = allocation; now_GR.update(); } }</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-update_Object__section_hmx_sgs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">update()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordUpdate_String" title="Updates the GlideRecord with any changes that have been made. If the record does not already exist, it is inserted.">update()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-updateMultiple"> <h2 class="title topictitle2" id="ariaid-title82">GlideRecord - updateMultiple()</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Updates each GlideRecord in a stated query with a specified set of changes.</span></p> <div class="section" id="r_GlideRecord-updateMultiple__section_pbf_jcw_1pb"> <p class="p">For information on adding journal entries, refer to the <a class="xref" href="../../GlideElement_global/concept/c_GlideElementAPI.html#r_GlideElement-setJournalEntry_Object_String" title="Adds a journal entry and author as a work note or comment field.">setJournalEntry()</a> method.</p> <p class="p">The <span class="keyword parmname">glide.db.forced.chunk.threshold</span> 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 <a class="xref" href="../administer/reference-pages/reference/r_AvailableSystemProperties.dita/r_AvailableSystemProperties.html" target="_blank" rel="noopener noreferrer">Available system properties</a>.</p> </div> <div class="section" id="r_GlideRecord-updateMultiple__id_n4j_xk4_f4b"> <div class="p"><div class="note"><span class="notetitle">Note:</span> To ensure expected results, use the <span class="keyword apiname">setValue()</span> method instead of direct assignments. That is, use <code class="ph codeph">gr.setValue('<field_name>', '4'));</code> instead of <code class="ph codeph">gr.<field_name> = 4</code>.</div> </div> <div class="p"><div class="note"><span class="notetitle">Note:</span> Do not use this method with the <span class="keyword apiname">chooseWindow()</span> or <span class="keyword apiname">setLimit()</span> methods when working with large tables.</div> </div> <p class="p">This method sets new values and does not clear existing values. To clear an existing value, use the <span class="keyword apiname">setValue()</span> method and set the field to <span class="keyword option">null</span>.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-updateMultiple__table_qwk_ysb_2r" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 160. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13631">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13634">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13637">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13631 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13634 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13637 "> </td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-updateMultiple__table_fj2_htb_2r" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 161. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13672">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13675">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13672 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13675 "> </td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-updateMultiple__example_o1q_yk4_f4b"> <p class="p">This example shows how to update the state of all active incidents to 4 - "Awaiting User Info".</p> <pre class="pre codeblock"><code>var now_GR = new GlideRecord('incident'); now_GR.addQuery('active', true); now_GR.setValue('state', 4); now_GR.updateMultiple();</code></pre> </div> <div class="section scoped-equivalent" id="r_GlideRecord-updateMultiple__section_ncr_rgs_mcb"><h3 class="title sectiontitle">Scoped equivalent</h3> <p class="p">To use the <span class="keyword apiname">updateMultiple()</span> method in a scoped application, use the corresponding scoped method: <a class="xref" href="../../glideRecordScoped/concept/c_GlideRecordScopedAPI.html#r_ScopedGlideRecordUpdateMultiple" title="Updates each GlideRecord in a stated query with a specified set of changes.">updateMultiple()</a>.</p> </div> </div> </div> <div class="topic reference nested1 api-method" id="r_GlideRecord-updateWithReferences_Object"> <h2 class="title topictitle2" id="ariaid-title83">GlideRecord - updateWithReferences(Object reason)</h2> <div class="body refbody"><p class="shortdesc"><span class="ph">Updates a record and also inserts or updates any related records with the information provided.</span></p> <div class="section"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-updateWithReferences_Object__id_ltp_jfd_3zb" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 162. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13784">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13787">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13790">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13784 ">reason</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13787 ">Object</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13790 ">Reason for the updates. The reason is displayed in the audit record.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="r_GlideRecord-updateWithReferences_Object__id_r1d_kfd_3zb" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 163. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13827">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d171457e13830">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13827 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d171457e13830 ">The sys_id for the record being updated.</td></tr></tbody></table> </div> </div> <div class="example" id="r_GlideRecord-updateWithReferences_Object__id_ud4_kfd_3zb"> <p class="p">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.</p> <pre class="pre codeblock"><code>var inc = new GlideRecord('incident'); inc.get(inc_sys_id); // Looking up an existing incident record where 'inc_sys_id' represents the sys_id of a incident record inc.caller_id.first_name = 'John'; inc.caller_id.last_name = 'Doe'; inc.updateWithReferences(); }</code></pre> </div> </div> </div> </div> </body></html></div>