GlideElement - Global
-
- UpdatedAug 1, 2024
- 23 minutes to read
- Xanadu
- API reference
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 glide record.
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().
GlideElement - canRead()
Determines 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 equivalent
To use the canRead() method in a scoped application, use the corresponding scoped method: canRead().
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 equivalent
To use the canWrite() method in a scoped application, use the corresponding scoped method: canWrite().
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 field has changed, false otherwise. |
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 equivalent
To use the changes() method in a scoped application, use the corresponding scoped method: changes().
GlideElement - changesFrom(Object value)
Determines if the previous value of the current field matches the specified object.
Name | Type | Description |
---|---|---|
value | Object | An object value to check against the previous value of the current field. |
Type | Description |
---|---|
Boolean | True if the previous value matches the parameter, false if it does not. |
Example
Scoped equivalent
To use the changesFrom() method in a scoped application, use the corresponding scoped method: changesFrom().
GlideElement - changesTo(Object value)
Determines if the new value of a field, after a change, matches the specified object.
Name | Type | Description |
---|---|---|
value | Object | An object value to check against the new value of the current field. |
Type | Description |
---|---|
Boolean | True if the new value matches the parameter, false if it does not. |
Example
Scoped equivalent
To use the changesTo() method in a scoped application, use the corresponding scoped method: changesTo().
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: 98000
Scoped equivalent
To use the dateNumericValue() method in a scoped application, use the corresponding scoped method: dateNumericValue().
GlideElement - debug(Object o)
Debugs the object and adds debug messages using setError(String).
Name | Type | Description |
---|---|---|
o | Object | An object to debug. |
Type | Description |
---|---|
void |
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 equivalent
To use the getAttribute() method in a scoped application, use the corresponding scoped method: getAttribute().
GlideElement - getBaseTableName()
Gets the base table of the field.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Name of the base table. This name might be different from the table that the field is defined on. See Table extension and classes in the product documentation. |
Example
The following example shows how to the base table for the Assignment Group field of an Incident record.
Output:
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 equivalent
To use the getBooleanAttribute() method in a scoped application, use the corresponding scoped method: getBooleanAttribute().
GlideElement - getChoices(String dependent)
Generates a choice list for a field. Returns the choice values from the base table only, not from the extended table.
Name | Type | Description |
---|---|---|
dependent | String | Optional. Field within the associated record on which the choice list field depends. |
Type | Description |
---|---|
array list | The choice values for the field. |
Example
Scoped equivalent
To use the getChoices() method in a scoped application, use the corresponding scoped method: getChoices().
GlideElement - getChoiceValue()
Gets the choice label for the current choice value.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The choice label. |
Example
The following example shows how to get the choice label for change request records with the a priority value of Normal.
Output:
Scoped equivalent
To use the getChoiceValue() method in a scoped application, use the corresponding scoped method: getChoiceValue().
GlideElement - getDebugCount()
Gets the number of debug messages logged by debug().
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of debug messages. |
GlideElement - getDependent()
Returns the field (element) that a specified field is dependent on.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Name of the field on which the current field depends. Null if no dependencies. |
Example
The following example shows how to find the parent field of the Configuration Item field using the getDependent() method.
Output:
GlideElement - getDependentTable()
Gets the table that the current table depends on.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The name of the table. |
GlideElement - getDisplayValue(Number maxChar)
Returns the formatted display value of the field.
Display values are manipulated based on the actual value in the database and user or system settings and preferences.
- Choice fields: The database value may be a number, but the display value will be more descriptive.
- Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
- Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
- Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
Name | Type | Description |
---|---|---|
maxChar | Number | Optional. Maximum number of characters to return. |
Type | Description |
---|---|
String | Display value of the field. |
Example
Scoped equivalent
To use the getDisplayValue() method in a scoped application, use the corresponding scoped method: getDisplayValue().
GlideElement - getDisplayValueExt(Number maxChar, String nullSub)
Returns the formatted display value of a field, or a specified substitute value if the display value is null or empty.
Display values are manipulated based on the actual value in the database and user or system settings and preferences.
- Choice fields: The database value may be a number, but the display value will be more descriptive.
- Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
- Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
- Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
Name | Type | Description |
---|---|---|
maxChar | Number | Optional. Maximum number of characters to be returned. Default: All |
nullSub | String | Value to return if the display value is null or empty. |
Type | Description |
---|---|
String | Formatted display value of the field, or the specified substitute value. |
Example
The following example shows how to display the two most recent active records in the Incident [incident] table.
Output:
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 equivalent
To use the getDisplayValueLang() method in a scoped application, use the corresponding scoped method: getDisplayValueLang().
GlideElement - getED()
Returns an element descriptor, which provides information about specific fields, rather than the data inside of those fields.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
ElementDescriptor | The field's element descriptor. |
Example
This example gets the fields and field descriptors for the current record.
Scoped equivalent
To use the getED() method in a scoped application, use the corresponding scoped method: getED().
GlideElement - getElementValue(String value)
Returns the value for the specified element.
Name | Type | Description |
---|---|---|
value | String | Element whose value you want returned. |
Type | Description |
---|---|
String | Value of the element. |
Example
Output
GlideElement - getError()
Returns any error message associated with the specified element.
Use the setError() method to set an error on a specific field (element).
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Error message currently set for the specified element. |
Example
This example shows how to set an error on the short_description element and then read the error back.
Output:
Example
This example shows how to use getError() in a function call.
GlideElement - getEscapedValue()
Gets the escaped value for the current element.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The escaped value of the current element. |
Example
The following example shows how to use the getEscapedValue() method to display the contents of an Incident short description field with escape characters.
Output:
GlideElement - getFieldStyle()
Gets the CSS style for the field.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The CSS style for the field. |
Example
GlideElement - getGlideObject()
Gets a glide object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | A Glide object. |
Example
GlideElement - getGlideRecord()
Gets a glide record.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideRecord | A glide record object. |
Example
Output
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
The following example shows how to get the HTML content of a meeting note.
Scoped equivalent
To use the getHTMLValue() method in a scoped application, use the corresponding scoped method: getHTMLValue().
GlideElement - getHTMLValueExt(Number maxChar, String nullSub)
Returns the HTML value of a field, or a specified substitute value if the HTML value is null or empty.
Name | Type | Description |
---|---|---|
maxChar | Number | The maximum number of characters to return. |
nullSub | String | The value to return if the HTML value is null or empty. |
Type | Description |
---|---|
String | The HTML value or the specified substitute value. |
Example
The following example shows how to get the HTML content of a meeting note.
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 equivalent
To use the getJournalEntry() method in a scoped application, use the corresponding scoped method: getJournalEntry().
GlideElement - getLabel()
Returns the object's label.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Object's label |
Example
Scoped equivalent
To use the getLabel() method in a scoped application, use the corresponding scoped method: getLabel().
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 equivalent
To use the getLabelLang() method in a scoped application, use the corresponding scoped method: getLabelLang().
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 equivalent
To use the getName() method in a scoped application, use the corresponding scoped method: getName().
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 equivalent
To use the getRefRecord() method in a scoped application, use the corresponding scoped method: getRefRecord().
GlideElement - getStyle()
Get the CSS style for the value.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The CSS style for the value. |
Example
GlideElement - getTableName()
Returns the name of the field's table.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Name of the table. This may be different from the table Class that the record is in. See Tables and Classes in the product documentation. |
Example
Scoped equivalent
To use the getTableName() method in a scoped application, use the corresponding scoped method: getTableName().
GlideElement - getTextAreaDisplayValue()
Retrieves the display value for the associated field and escapes the HTML.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Escaped display value HTML for the associated field. |
Example
The following example retrieves the display value of a KB article.
Output:
GlideElement - getValue()
Returns the value of the field in the database.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The value of the field. |
Example
The following example retrieves the value of a specified field in the database.
Output:
GlideElement - getXHTMLValue()
Retrieves the XHTML value of a field.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The XHTML value |
GlideElement - getXMLValue()
Gets the XML value of a field as a string.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The XML value |
GlideElement - hasAttribute(String attributeName)
Determines whether a field has a particular attribute.
Name | Type | Description |
---|---|---|
attributeName | String | The attribute to check for |
Type | Description |
---|---|
Boolean | True if the field has the attribute, false otherwise. |
Example
GlideElement - hasRightsTo(String operationName)
Determines if the user has the right to perform a particular operation.
Name | Type | Description |
---|---|---|
operationName | String | Name of the operation to check for |
Type | Description |
---|---|
Boolean | True if the user has permission to perform the operation, false
otherwise. Flag that indicates whether a user has permission to perform an operation. Valid values:
|
Example
The following example shows how to determine if a user has rights to read a specific table.
Output:
GlideElement - hasValue()
Determines if the field has a value.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the field has a value, false otherwise. |
GlideElement - nil()
Determines whether the field is null.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the field is null or an empty string, false otherwise. |
Example
Scoped equivalent
To use the nil() method in a scoped application, use the corresponding scoped method: nil().
GlideElement - setDateNumericValue(Number milliseconds)
Sets the duration field to a 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 |
---|---|---|
milliseconds | Number | Number of milliseconds spanned by the duration. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setDateNumericValue() method in a scoped application, use the corresponding scoped method: setDateNumericValue().
GlideElement - setDisplayValue(Object displayValue)
Sets the display value of the field.
Name | Type | Description |
---|---|---|
displayValue | Object | Value to be displayed. |
Type | Description |
---|---|
void |
Scoped equivalent
To use the setDisplayValue() method in a scoped application, use the corresponding scoped method: setDisplayValue().
GlideElement - setError(String message)
Adds an error message to the associated field (element).
You can retrieve the error message using the getError() method.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
None |
Example
Scoped equivalent
To use the setError() method in a scoped application, use the corresponding scoped method: setError().
GlideElement - setInitialValue(Object value)
Sets the initial value of a field.
This method had been deprecated. Use GlideElement - setValue(Object value) for this functionality.
Name | Type | Description |
---|---|---|
value | Object | Initial value for the field. |
Type | Description |
---|---|
void |
GlideElement - setJournalEntry(String entry, String userName)
Adds a journal entry and author as a work note or comment field.
Name | Type | Description |
---|---|---|
entry | String | Content of the journal entry. |
userName | String | Optional. The user to attribute the journal entry to. |
Type | Description |
---|---|
None |
Example
The following example shows how to add a work note and its author to a record.
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 | The value the field is to be set to. |
Type | Description |
---|---|
void |
Example
Set the value passing a string.
Example
Set the value passing an object.
Scoped equivalent
To use the setValue() method in a scoped application, use the corresponding scoped method: setValue().
GlideElement - toString()
Converts the field's value to a string.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The field's value as a string. |
Example
Scoped equivalent
To use the toString() method in a scoped application, use the corresponding scoped method: toString().
On this page
- GlideElement - canCreate()
- GlideElement - canRead()
- GlideElement - canWrite()
- GlideElement - changes()
- GlideElement - changesFrom(Object value)
- GlideElement - changesTo(Object value)
- GlideElement - dateNumericValue()
- GlideElement - debug(Object o)
- GlideElement - getAttribute(String attributeName)
- GlideElement - getBaseTableName()
- GlideElement - getBooleanAttribute(String attributeName)
- GlideElement - getChoices(String dependent)
- GlideElement - getChoiceValue()
- GlideElement - getDebugCount()
- GlideElement - getDependent()
- GlideElement - getDependentTable()
- GlideElement - getDisplayValue(Number maxChar)
- GlideElement - getDisplayValueExt(Number maxChar, String nullSub)
- GlideElement - getDisplayValueLang(String language)
- GlideElement - getED()
- GlideElement - getElementValue(String value)
- GlideElement - getError()
- GlideElement - getEscapedValue()
- GlideElement - getFieldStyle()
- GlideElement - getGlideObject()
- GlideElement - getGlideRecord()
- GlideElement - getHTMLValue(Number maxChars)
- GlideElement - getHTMLValueExt(Number maxChar, String nullSub)
- GlideElement - getJournalEntry(Number mostRecent)
- GlideElement - getLabel()
- GlideElement - getLabelLang(String language)
- GlideElement - getName()
- GlideElement - getRefRecord()
- GlideElement - getStyle()
- GlideElement - getTableName()
- GlideElement - getTextAreaDisplayValue()
- GlideElement - getValue()
- GlideElement - getXHTMLValue()
- GlideElement - getXMLValue()
- GlideElement - hasAttribute(String attributeName)
- GlideElement - hasRightsTo(String operationName)
- GlideElement - hasValue()
- GlideElement - nil()
- GlideElement - setDateNumericValue(Number milliseconds)
- GlideElement - setDisplayValue(Object displayValue)
- GlideElement - setError(String message)
- GlideElement - setInitialValue(Object value)
- GlideElement - setJournalEntry(String entry, String userName)
- GlideElement - setValue(Object value)
- GlideElement - toString()