GlideElement - Scoped
-
- UpdatedJan 30, 2025
- 13 minutes to read
- Yokohama
- API implementation and reference
The scoped GlideElement API provides a number of convenient script methods for dealing with fields and their values. Scoped GlideElement methods are available for the fields of the current glide record.
Scoped GlideElement - canCreate()
Determines if the user's role permits the creation of new entries in the associated field.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the current user has permissions to create new
entries in the associated field. Possible values:
|
Example
The following example shows how to determine if the user has permissions to create entries for the three most recent records in the Problem [problem] table.
Output:
Scoped equivalent
To use the canCreate() method in a scoped application, use the corresponding scoped method: canCreate().
Scoped GlideElement - canRead()
Indicates whether the user's role permits them to read the associated GlideRecord.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the field can be read, false otherwise. |
Example
The following example shows how to get a list of active Incident records with a readable Short Description field.
Output:
Scoped GlideElement - canWrite()
Determines whether the user's role permits them to write to the associated GlideRecord.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the user can write to the field, false otherwise. |
Example
The following example shows how to get a list of active Incident records with a writeable Short Description field.
Output:
Scoped GlideElement - changes()
Determines if the current field has been modified. This functionality is available for all available data types, except Journal fields.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the fields have been changed, false if the field has not. |
Example
The following example from a business rule shows how to create an event in the EventQueue if the value of the assigned_to field changes.
Scoped GlideElement - changesFrom(Object o)
Determines if the previous value of the current field matches the specified object.
Name | Type | Description |
---|---|---|
o | Object | An object value to check against the previous value of the current field. |
Type | Description |
---|---|
Boolean | True if the previous value matches, false if it does not. |
Example
Scoped GlideElement - changesTo(Object o)
Determines if the new value of a field, after a change, matches the specified object.
Name | Type | Description |
---|---|---|
o | Object | An object value to check against the new value of the current field. |
Type | Description |
---|---|
Boolean | True if the previous value matches, false if it does not. |
Example
Scoped GlideElement - dateNumericValue()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for a duration field. Does not require the creation of a GlideDateTime object because the duration field is already a GlideDateTime object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | Number of milliseconds since January 1, 1970, 00:00:00 GMT. |
Example
Output:
Scoped GlideElement - getAttribute(String attributeName)
Returns the value of the specified attribute from the dictionary.
If the attribute is a boolean attribute, use getBooleanAttribute(String) to get the value as a boolean rather than as a string.
Name | Type | Description |
---|---|---|
attributeName | String | Attribute name |
Type | Description |
---|---|
String | Attribute value |
Example
Scoped GlideElement - getBooleanAttribute(String attributeName)
Returns the Boolean value of the specified attribute from the dictionary.
To get the value as a string, use getAttribute(string).
Name | Type | Description |
---|---|---|
attributeName | String | Attribute name |
Type | Description |
---|---|
Boolean | Boolean value of the attribute. Returns false if the attribute does not exist. |
Example
The following example shows how to get Boolean values of the ignore_filter_on_new attribute for two fields.
Output:
Scoped GlideElement - getChoices(String dependent)
Returns the choice list for a specified field.
The field for which to return the choice list is specified in the method call. For example:
var choices = glideRecord.urgency.getChoices();
. For information on
choice list field types and their associated capabilities, see Choice list field type.
Name | Type | Description |
---|---|---|
dependent | String | Optional. Field within the associated record on which the choice list field depends. |
Type | Description |
---|---|
Array | List of possible values for the choice list, which are the values in the Choice [sys_choice] table. If the dependent parameter is passed, the return results reflect only those choices available for the specified dependent field. |
Example
Scoped GlideElement - getChoiceValue()
Returns the choice label for the current choice.
A choice has a value (number) and a label (string). This method returns the label.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The selected choice's label. |
Example
Output:
Scoped GlideElement - getDecryptedValue()
Returns the clear text value for Password (2 way encrypted) fields in scoped applications.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The clear text password. |
Example
Scoped GlideElement - getDisplayValue(Number maxCharacters)
Returns the formatted display value of a specified field from an associated GlideRecord object.
Display values are manipulated based on the actual value in the database and user or system settings and preferences.
- Choice fields: The database value may be a number, but the display value will be more descriptive.
- Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
- Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
- Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
For more information on display values, see Display values.
Name | Type | Description |
---|---|---|
maxCharacters | Number | Optional. Maximum characters desired. Default: All |
Type | Description |
---|---|
String | Display value of the specified field. |
Example
The following example shows how to retrieve the display value of the priority field in an incident record.
Output:
Example
The following example shows how to retrieve both the display value and internal value of specified fields in the incident database.
Output:
Scoped GlideElement - getDisplayValueLang(String language)
Gets the display value of the field in the language passed as a parameter.
The result is only applicable to translatable field types such as Choice, Translated Field, and Translated Text. For other field types, the result defaults to getDisplayValue().
You must have the corresponding language plugin to retrieve a translated value. For information, see Activate a language.
See also Scoped GlideElement - getLabelLang(String language).
Name | Type | Description |
---|---|---|
language | String | Language tag conforming with IETF BCP-47. |
Type | Description |
---|---|
String | Display value of the field in the language passed. If a translation isn't available, the method retrieves a value translated in the language of the current user. If a translation isn’t available, the result defaults to English. |
Example
The following example shows how to get the original text and German-translated text from the Accept (UI View) title field.
Output:
Scoped GlideElement - getED()
Returns the field's element descriptor.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideElementDescriptor | The field's element descriptor. |
Example
Scoped GlideElement - getGlobalDisplayValue()
Returns the phone number in international format.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Phone number in international format. |
Example
The following example shows how to get the phone number of a walk-up location. This example requires the Walk-up Experience plugin.
Output:
Scoped GlideElement - getHTMLValue(Number maxChars)
Returns the HTML value of a field.
Name | Type | Description |
---|---|---|
maxChars | Number | Optional. Maximum number of characters to return. |
Type | Description |
---|---|
String | HTML value for the field. |
Example
Scoped GlideElement - getJournalEntry(Number mostRecent)
Returns either the most recent journal entry or all journal entries.
Name | Type | Description |
---|---|---|
mostRecent | Number | If 1, returns the most recent entry. If -1, returns all journal entries. |
Type | Description |
---|---|
String | For the most recent entry, returns a string that contains the field label, timestamp, and user display name of the journal entry. For all journal entries, returns the same information for all journal entries ever entered as a single string with each entry delimited by "\n\n". |
Example
Scoped GlideElement - getLabel()
Returns the object label.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Object label |
Example
Scoped GlideElement - getLabelLang(String language)
Gets the label value of the field in the language passed as a parameter.
You must have the corresponding language plugin to retrieve a translated value. For information, see Activate a language.
Name | Type | Description |
---|---|---|
language | String | Language tag conforming with IETF BCP-47. |
Type | Description |
---|---|
String | Value of the field label in the language passed. If a translation isn't available, the method retrieves a value translated in the language of the current user. If a translation isn’t available, the result defaults to English. |
Example
The following example shows how to get the original label text and its German translation of the Accept (UI View) title.
Output:
Scoped GlideElement - getName()
Returns the name of the field.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Field name. |
Example
The following example shows how to get the name and other values for each field in a sys_user record.
Output. Results include 62 fields and have been truncated with ellipsis points (…) to save space.
Scoped GlideElement - getReferenceTable()
Gets the table name for a reference element.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Table name of the reference. |
Example
Scoped GlideElement - getRefRecord()
Returns a GlideRecord object for a given reference element.
For calculated fields, this method fetches the referenced record and runs a calculation on a scripted default value.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideRecord | A GlideRecord object |
Example
Scoped GlideElement - getTableName()
Returns the name of the table on which the field resides.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Name of the table. The returned value may be different from the table Class that the record is in. See Tables and Classes in the product documentation. |
Example
Scoped GlideElement - nil()
Determines if a field is null.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the field is null. Possible values:
|
Example
Output:
Scoped GlideElement - setDateNumericValue(Number milliseconds)
Sets the value of a date/time element to the specified number of milliseconds since January 1, 1970 00:00:00 GMT.
When called, setDateNumericValue() automatically creates the necessary GlideDateTime/GlideDate/GlideDuration object, and then sets the element to the specified value.
Name | Type | Description |
---|---|---|
milliseconds | Number | Number of milliseconds since 1/1/1970 |
Type | Description |
---|---|
void |
Example
Scoped GlideElement - setDisplayValue(Object value)
Sets the display value of the field.
Name | Type | Description |
---|---|---|
value | Object | The value to set for the field. |
Type | Description |
---|---|
void |
Example
Scoped GlideElement - setError(String errorMessage)
Adds an error message. Available in Fuji patch 3.
Name | Type | Description |
---|---|---|
errorMessage | String | The error message. |
Type | Description |
---|---|
void |
Example
Scoped GlideElement - setPhoneNumber(Object phoneNumber, Boolean strict)
Sets the field to the specified phone number.
This method is only available on a phone number GlideElement.
Name | Type | Description |
---|---|---|
phoneNumber | Object | The phone number to set. This can be in either the international or local format. |
strict | Boolean | When true, specifies that the number specified must match the correct format. When false, the system attempts to correct an improperly formatted phone number. |
Type | Description |
---|---|
Boolean | Flag that indicates whether the phone number value was set. Possible values:
|
Example
The following example shows how to set the phone number of a walk-up location. This example requires the Walk-up Experience plugin.
Output:
Scoped GlideElement - setValue(Object value)
Sets the value of a field.
- Not for authentication with password2 fields
- The setValue() method passes password2 data as clear text, which results in an error about expecting encrypted data. Additionally, using the setValue() method for password2 fields exposes data that
should be encrypted.
For password2 authentication, use the setDisplayValue() method instead.
Name | Type | Description |
---|---|---|
value | Object | Object value to set the field to. |
Type | Description |
---|---|
None |
Example
Set the value passing a string.
Example
Set the value passing an object.
Scoped GlideElement - toString()
Converts the value of a GlideRecord field to a string.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Value as a string. |
Example
Output:
On this page
- Scoped GlideElement - canCreate()
- Scoped GlideElement - canRead()
- Scoped GlideElement - canWrite()
- Scoped GlideElement - changes()
- Scoped GlideElement - changesFrom(Object o)
- Scoped GlideElement - changesTo(Object o)
- Scoped GlideElement - dateNumericValue()
- Scoped GlideElement - getAttribute(String attributeName)
- Scoped GlideElement - getBooleanAttribute(String attributeName)
- Scoped GlideElement - getChoices(String dependent)
- Scoped GlideElement - getChoiceValue()
- Scoped GlideElement - getDecryptedValue()
- Scoped GlideElement - getDisplayValue(Number maxCharacters)
- Scoped GlideElement - getDisplayValueLang(String language)
- Scoped GlideElement - getED()
- Scoped GlideElement - getGlobalDisplayValue()
- Scoped GlideElement - getHTMLValue(Number maxChars)
- Scoped GlideElement - getJournalEntry(Number mostRecent)
- Scoped GlideElement - getLabel()
- Scoped GlideElement - getLabelLang(String language)
- Scoped GlideElement - getName()
- Scoped GlideElement - getReferenceTable()
- Scoped GlideElement - getRefRecord()
- Scoped GlideElement - getTableName()
- Scoped GlideElement - nil()
- Scoped GlideElement - setDateNumericValue(Number milliseconds)
- Scoped GlideElement - setDisplayValue(Object value)
- Scoped GlideElement - setError(String errorMessage)
- Scoped GlideElement - setPhoneNumber(Object phoneNumber, Boolean strict)
- Scoped GlideElement - setValue(Object value)
- Scoped GlideElement - toString()