---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideElement - Scoped

# GlideElement - Scoped {#ariaid-title1}

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() {#ariaid-title2}

Determines if the user's role permits the creation of new entries in the associated
field.
{#SGE-canCreate__table_hq2_gmp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#SGE-canCreate__table_hq2_gmp_fz} {#SGE-canCreate__table_iq2_gmp_fz__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the current user has permissions to create new entries in the associated field. Possible values: * true: User can create new entries. * false: User cannot create new entries. {#SGE-canCreate__ul_w1j_ggm_vrb} |
[Table 2. Returns]

{#SGE-canCreate__table_iq2_gmp_fz}  
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.

    var gr = new GlideRecord('problem');

    // Get records in new state in Problem Table
    gr.addQuery('state','101');

    // Sort records in order of recent to earlier Created Date
    gr.orderByDesc('sys_created_on');

    // Limit the query to three records
    gr.setLimit(3); 
    gr.query();

    while(gr.next()){
      if(gr.short_description.canCreate()){ ///check to see if the current user is allowed to create the record
      gs.info("I can create new records for the field Problem statement for - " + gr.number);
      }
    }

Output:

    I can create new records for the field Problem statement for - PRB0000004
    I can create new records for the field Problem statement for - PRB0001000
    I can create new records for the field Problem statement for - PRB0001001

### Scoped equivalent {#SGE-canCreate__section_k21_xyr_mcb}

To use the canCreate() method in a scoped application, use the
corresponding scoped method: [canCreate()](https://servicenow-prod.fluidtopics.net/y~_OwldB4lvmYtOvTK4Ajg#SGE-canCreate "Determines if the user's role permits the creation of new entries in the associated field.").

## Scoped GlideElement - canRead() {#ariaid-title3}

Indicates whether the user's role permits them to read the associated
GlideRecord.
{#SGE-canRead__table_wdj_mnp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#SGE-canRead__table_wdj_mnp_fz} {#SGE-canRead__table_xdj_mnp_fz__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the field can be read, false otherwise. |
[Table 4. Returns]

{#SGE-canRead__table_xdj_mnp_fz}  
The following example shows how to get a list of active Incident records with a readable
Short Description field.

    var grIncident = new GlideRecord('incident');
    grIncident.addEncodedQuery("active=true"); //Query the Incident table for active incidents
    grIncident.orderByDesc('number');
    grIncident.setLimit(3); // limit to three results for example
    grIncident.query();

    while (grIncident.next()) {
        if (grIncident.short_description.canRead()) { //check to see if the current user is allowed to read the record
            gs.info('You have permission to read the short description of: ' + grIncident.number + ' ' + grIncident.short_description);
        }
    }

Output:

    *** Script: You have permission to read the short description of: INC0009009 Unable to access the shared folder.
    *** Script: You have permission to read the short description of: INC0009005 Email server is down.
    *** Script: You have permission to read the short description of: INC0009001 Unable to post content on a Wiki page

## Scoped GlideElement - canWrite() {#ariaid-title4}

Determines whether the user's role permits them to write to the associated
GlideRecord.
{#SGE-canWrite__table_myz_1pp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 5. Parameters]

{#SGE-canWrite__table_myz_1pp_fz} {#SGE-canWrite__table_nyz_1pp_fz__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the user can write to the field, false otherwise. |
[Table 6. Returns]

{#SGE-canWrite__table_nyz_1pp_fz}  
The following example shows how to get a list of active Incident records with a writeable
Short Description field.

    var grIncident = new GlideRecord('incident');
    grIncident.addEncodedQuery("active=true"); //Query the Incident table for active incidents
    grIncident.orderByDesc('number');
    grIncident.setLimit(3); // limit to three results for example
    grIncident.query();

    while (grIncident.next()) {
        if (grIncident.short_description.canWrite()) { //check to see if the current user is allowed to write to the record
            gs.info('You have permission to write to the short description of: ' + grIncident.number + ' ' + grIncident.short_description);
        }
    }

Output:

    *** Script: You have permission to write to the short description of: INC0009009 Unable to access the shared folder.
    *** Script: You have permission to write to the short description of: INC0009005 Email server is down.
    *** Script: You have permission to write to the short description of: INC0009001 Unable to post content on a Wiki page

## Scoped GlideElement - changes() {#ariaid-title5}

Determines if the current field has been modified. This functionality is available for
all available data types, except Journal fields.
Note:  
The changes() method is not supported within ACL scripts.  
Note:  
If the GlideRecord on which you are performing this method has only been initialized and read, and has not been written, the underlying before-and-after values are the same. In this case, the method returns "false", as there has been no change to the data store.

Business rule execution
:   The ServiceNow AI Platform invokes business rules (BEFORE or AFTER) before resetting the internal previous values for columns (GlideElement objects) to the
    current values.  
    This sequence enables the following actions:

    * Triggering an AFTER business rule on \<column\>.changes conditions.
    * Accessing the previous GlideRecord object in the script section.
    {#r_ScopedGlideElementChanges__ul_k4p_hn5_m3c}
:   Even in AFTER business rules, `current.<field>.changes()` returns `true` because the internal previous values haven't been reset yet. The condition
    `current.<field>.value != previous.<field>.value` also returns `true`.
:   Previous values are only reset after the following activities:

    * The database update is complete.
    * All AFTER business rules have been processed.

    {#r_ScopedGlideElementChanges__ul_ov1_nn5_m3c}

    Inside an AFTER business rule, the changes() method still returns true if the field value was modified, even though the rule executes after the update.
{#r_ScopedGlideElementChanges__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#r_ScopedGlideElementChanges__table_vy2_525_jq} {#r_ScopedGlideElementChanges__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the fields have been changed, false if the field has not. |
[Table 8. Returns]

{#r_ScopedGlideElementChanges__table_qpt_3f5_jq}  
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. For a comprehensive example, see [Sample scripts from the change events business rule](https://www.servicenow.com/docs/access?context=r_ChangeEventsSampleScripts&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).

    if (!current.assigned_to.nil() && current.assigned_to.changes()) {
      gs.eventQueue('incident.assigned', current, current.assigned_to.getDisplayValue(), previous.assigned_to.getDisplayValue());
    }

## Scoped GlideElement - changesFrom(Object o) {#ariaid-title6}

Determines if the previous value of the current field matches the specified
object.
Note:  
If the GlideRecord on which you are performing this method has only been initialized and read, and has not been written, the underlying before-and-after values are the same. In this case, the method returns "false", as there has been no change to the data store.
{#r_ScopedGlideElementChangesFrom_Object_o__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| o | Object | An object value to check against the previous value of the current field. |
[Table 9. Parameters]

{#r_ScopedGlideElementChangesFrom_Object_o__table_vy2_525_jq} {#r_ScopedGlideElementChangesFrom_Object_o__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the previous value matches, false if it does not. |
[Table 10. Returns]

{#r_ScopedGlideElementChangesFrom_Object_o__table_qpt_3f5_jq}  

    // The following example shows that in a business rule, if "active" field is changed from true, 
    // insert a event in the EventQueue.
    if (current.active.changesFrom(true)) {
      gs.eventQueue("incident.inactive", current, current.incident_state, previous.incident_state);
    }

## Scoped GlideElement - changesTo(Object o) {#ariaid-title7}

Determines if the new value of a field, after a change, matches the specified
object.
Note:  
The changesTo() method is not supported within ACL scripts.  
Note:  
If the GlideRecord on which you are performing this method has only been initialized and read, and has not been written, the underlying before-and-after values are the same. In this case, the method returns "false", as there has been no change to the data store.
{#r_ScopedGlideElementChangesTo_Object_o__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| o | Object | An object value to check against the new value of the current field. |
[Table 11. Parameters]

{#r_ScopedGlideElementChangesTo_Object_o__table_vy2_525_jq} {#r_ScopedGlideElementChangesTo_Object_o__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the previous value matches, false if it does not. |
[Table 12. Returns]

{#r_ScopedGlideElementChangesTo_Object_o__table_qpt_3f5_jq}  

    // The following example shows that in a business rule, if "active" field is changed to false, 
    // insert a event in the EventQueue.
    if (current.active.changesTo(false)) {
      gs.eventQueue("incident.inactive", current, current.incident_state, previous.incident_state);
    }

## Scoped GlideElement - dateNumericValue() {#ariaid-title8}

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.
{#SGE-dateNumericValue__table_wzd_zlp_j2b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#SGE-dateNumericValue__table_wzd_zlp_j2b} {#SGE-dateNumericValue__table_xzd_zlp_j2b__entry__2}

| Type | Description |
|-|-|
| Number | Number of milliseconds since January 1, 1970, 00:00:00 GMT. |
[Table 14. Returns]

{#SGE-dateNumericValue__table_xzd_zlp_j2b}  

    var inc = new GlideRecord('incident');
    inc.get('17c90efb13418700cc36b1422244b05d');
    gs.info(inc.calendar_duration.dateNumericValue());

Output:

    98000

## Scoped GlideElement - getAttribute(String attributeName) {#ariaid-title9}

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.
{#SGE-getAttribute_String__table_dsj_hqp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| attributeName | String | Attribute name |
[Table 15. Parameters]

{#SGE-getAttribute_String__table_dsj_hqp_fz} {#SGE-getAttribute_String__table_esj_hqp_fz__entry__2}

| Type | Description |
|-|-|
| String | Attribute value |
[Table 16. Returns]

{#SGE-getAttribute_String__table_esj_hqp_fz}  

    doit();
    function doit() {
      var now_GR = new GlideRecord('sys_user');
      now_GR.query("user_name","admin");
      if (now_GR.next()) {
        gs.info("we got one");
        gs.info(now_GR.location.getAttribute("tree_picker"));
      }
    }

## Scoped GlideElement - getBooleanAttribute(String attributeName) {#ariaid-title10}

Returns the Boolean value of the specified attribute from the dictionary.
To get the value as a string, use getAttribute(string).
{#SGE-getBooleanAttribute_String__table_fv5_prp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| attributeName | String | Attribute name |
[Table 17. Parameters]

{#SGE-getBooleanAttribute_String__table_fv5_prp_fz} {#SGE-getBooleanAttribute_String__table_gv5_prp_fz__entry__2}

| Type | Description |
|-|-|
| Boolean | Boolean value of the attribute. Returns false if the attribute does not exist. |
[Table 18. Returns]

{#SGE-getBooleanAttribute_String__table_gv5_prp_fz}  
The following example shows how to get Boolean values of the ignore_filter_on_new attribute for two fields.

    var inc = new GlideRecord('incident');
    inc.query();

    if (inc.next())
     {
       // opened_by field has attribute "ignore_filter_on_new = true"
       gs.info(inc.opened_by.getBooleanAttribute("ignore_filter_on_new"));

      // short_description field does not have attribute ignore_filter_on_new
       gs.info(inc.short_description.getBooleanAttribute("ignore_filter_on_new"));
     }

Output:

    true
    false

## Scoped GlideElement - getChoices(String dependent) {#ariaid-title11}

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](https://www.servicenow.com/docs/access?context=c_ChoiceLists&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).
{#r_ScopedGlideElementGetChoices_String_dependent__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| dependent | String | Optional. Field within the associated record on which the choice list field depends. |
[Table 19. Parameters]

{#r_ScopedGlideElementGetChoices_String_dependent__table_vy2_525_jq} {#r_ScopedGlideElementGetChoices_String_dependent__table_qpt_3f5_jq__entry__2}

| 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. |
[Table 20. Returns]

{#r_ScopedGlideElementGetChoices_String_dependent__table_qpt_3f5_jq}  

    var glideRecord = new GlideRecord('incident'); 
    glideRecord.query('priority','1'); 
    glideRecord.next(); 
     
    // urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3
    var choices = glideRecord.urgency.getChoices();

## Scoped GlideElement - getChoiceValue() {#ariaid-title12}

Returns the choice label for the current choice.
A choice has a value (number) and a label (string). This method returns the label.
{#r_ScopedGlideElementGetChoiceValue__table_kgb_3z3_ps__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 21. Parameters]

{#r_ScopedGlideElementGetChoiceValue__table_kgb_3z3_ps} {#r_ScopedGlideElementGetChoiceValue__table_lgb_3z3_ps__entry__2}

| Type | Description |
|-|-|
| String | The selected choice's label. |
[Table 22. Returns]

{#r_ScopedGlideElementGetChoiceValue__table_lgb_3z3_ps}  

    var glideRecord = new GlideRecord('incident'); 
    glideRecord.query('priority','1'); 
    glideRecord.next(); 
     
    // urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3
    var choiceLabel = glideRecord.urgency.getChoiceValue(); 
    gs.info(choiceLabel);

Output:

    1 - High

## Scoped GlideElement - getDecryptedValue() {#ariaid-title13}

Returns the clear text value for Password (2 way encrypted) fields in scoped
applications.
{#SGE-getDecryptedValue__table_xd2_gsp_jz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 23. Parameters]

{#SGE-getDecryptedValue__table_xd2_gsp_jz} {#SGE-getDecryptedValue__table_yd2_gsp_jz__entry__2}

| Type | Description |
|-|-|
| String | The clear text password. |
[Table 24. Returns]

{#SGE-getDecryptedValue__table_yd2_gsp_jz}  

    var tablename = 'x_scoped_app_table'
    var CI = new GlideRecord(tablename);  
    CI.addQuery('number', '0001002'); 
    CI.query(); 
    CI.next(); 

    var password = CI.password_field
    var decrypted = password.getDecryptedValue(); 
    gs.info(decrypted);

Output:

    x_scoped_app: cleartextpassword

## Scoped GlideElement - getDisplayValue(Number maxCharacters) {#ariaid-title14}

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.  
The display value that is returned is dependent on the field type.

* 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.
{#r_ScopedGlideElementGetDisplayValue_Number_maxCharacters__ul_ok1_cbv_hsb}

For more information on display values, see [Display values](https://www.servicenow.com/docs/access?context=c_DisplayValues&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).
{#r_ScopedGlideElementGetDisplayValue_Number_maxCharacters__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| maxCharacters | Number | Optional. Maximum characters desired. Default: All |
[Table 25. Parameters]

{#r_ScopedGlideElementGetDisplayValue_Number_maxCharacters__table_vy2_525_jq} {#r_ScopedGlideElementGetDisplayValue_Number_maxCharacters__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Display value of the specified field. |
[Table 26. Returns]

{#r_ScopedGlideElementGetDisplayValue_Number_maxCharacters__table_qpt_3f5_jq}  
The following example shows how to retrieve the display value of the priority field in an
incident record.

    var glideRecord = new GlideRecord('incident');
    glideRecord.query('priority','1');
    glideRecord.next();
    gs.info(glideRecord.priority.getDisplayValue());

Output:

    1 - Critical

The following example shows how to retrieve both the display value and internal value of specified fields in the incident database.

    var now_GR = new GlideRecord('incident');
    now_GR.get('9c573169c611228700193229fff72400'); //INC0000001
    gs.info('Display Values:');
    gs.info('Opened at ' + now_GR.opened_at.getDisplayValue());
    gs.info('Opened by ' + now_GR.opened_by.getDisplayValue());
    gs.info('Priority ' + now_GR.priority.getDisplayValue());
    gs.info('Values:');
    gs.info('Opened at ' + now_GR.opened_at.getValue());
    gs.info('Opened by ' + now_GR.opened_by.getValue());
    gs.info('Priority ' + now_GR.priority.getValue());

Output:

    Display Values:
    Opened at 2022-02-01 15:09:51
    Opened by Joe Employee
    Priority 1 - Critical
    Values:
    Opened at 2022-02-01 23:09:51
    Opened by 681ccaf9c0a8016400b98a06818d57c7
    Priority 1

## Scoped GlideElement - getDisplayValueLang(String language) {#ariaid-title15}

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()](https://servicenow-prod.fluidtopics.net/y~_OwldB4lvmYtOvTK4Ajg#r_ScopedGlideElementGetDisplayValue_Number_maxCharacters "Returns the formatted display value of a specified field from an associated GlideRecord object.").

You must have the corresponding language plugin to retrieve a translated value. For information, see [Activate a language](https://www.servicenow.com/docs/access?context=t_ActivateALanguage&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).{#SGE-getDisplayValueLang_S__p_SGE-getDspOrLabellLang-plugins}

See also [Scoped GlideElement - getLabelLang(String language)](https://servicenow-prod.fluidtopics.net/y~_OwldB4lvmYtOvTK4Ajg#SGE-getLabelLang_S "Gets the label value of the field in the language passed as a parameter.").
{#SGE-getDisplayValueLang_S__table_GE-language-parm__entry__3}

| Name | Type | Description |
|-|-|-|
| language | String | Language tag conforming with IETF BCP-47. |
[Table 27. Parameters]

{#SGE-getDisplayValueLang_S__table_GE-language-parm} {#SGE-getDisplayValueLang_S__table_qpt_3f5_jq__entry__2}{#SGE-getDisplayValueLang_S__ph_getDisOrLblLang_returns_if}

| 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. |
[Table 28. Returns]

{#SGE-getDisplayValueLang_S__table_qpt_3f5_jq}  
The following example shows how to get the original text and German-translated text from the Accept (UI View) title field.

    var uiView = new GlideRecord("sys_ui_view");
    uiView.get("fa776f6d97700100f309124eda2975bc");

    gs.info("getDisplayValue: " + uiView.getElement("title").getDisplayValue());
    gs.info("getDisplayValueLang: " + uiView.getElement("title").getDisplayValueLang("de"));

Output:

    getDisplayValue: Accept
    getDisplayValueLang: Akzeptieren

## Scoped GlideElement - getED() {#ariaid-title16}

Returns the field's element descriptor.
{#r_ScopedGlideElementGetED__table_k23_ps3_yr__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 29. Parameters]

{#r_ScopedGlideElementGetED__table_k23_ps3_yr} {#r_ScopedGlideElementGetED__table_l23_ps3_yr__entry__2}

| Type | Description |
|-|-|
| GlideElementDescriptor | The field's element descriptor. |
[Table 30. Returns]

{#r_ScopedGlideElementGetED__table_l23_ps3_yr}  

    var grInc = new GlideRecord('incident');
    grInc.query('priority', '1');
     
    var field = grInc.getElement('priority');
    var ed = field.getED();

## Scoped GlideElement - getGlobalDisplayValue() {#ariaid-title17}

Returns the phone number in international format.
{#r_SGE-getGlobalDisplayValue__table_nfm_lq2_bx__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 31. Parameters]

{#r_SGE-getGlobalDisplayValue__table_nfm_lq2_bx} {#r_SGE-getGlobalDisplayValue__table_ofm_lq2_bx__entry__2}

| Type | Description |
|-|-|
| String | Phone number in international format. |
[Table 32. Returns]

{#r_SGE-getGlobalDisplayValue__table_ofm_lq2_bx}  
The following example shows how to get the phone number of a walk-up location. This example
requires the Walk-up Experience plugin.

    // Passing walkup location name and closed phone number in parameters
    setWalkupLocPhone('Santa Clara Tech Lounge','phone_number');

    function setWalkupLocPhone(locName, field) {
      var walkupLoc = new GlideRecord('wu_location_queue');
      walkupLoc.addQuery('name',locName);
      walkupLoc.query();
      walkupLoc.next();

      // Returns the phone number of walk-up location queue in international format
      gs.info(walkupLoc[field].getGlobalDisplayValue());
    }

Output:

    +91 98124 56789

## Scoped GlideElement - getHTMLValue(Number maxChars) {#ariaid-title18}

Returns the HTML value of a field.
{#SGE-getHTMLValue_Number__table_p1h_2tp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| maxChars | Number | Optional. Maximum number of characters to return. |
[Table 33. Parameters]

{#SGE-getHTMLValue_Number__table_p1h_2tp_fz} {#SGE-getHTMLValue_Number__table_q1h_2tp_fz__entry__2}

| Type | Description |
|-|-|
| String | HTML value for the field. |
[Table 34. Returns]

{#SGE-getHTMLValue_Number__table_q1h_2tp_fz}  

    var inccause = new GlideRecord("incident");
    inccause.short_description = current.short_description;
    inccause.comments = current.comments.getHTMLValue();
    inccause.insert();

## Scoped GlideElement - getJournalEntry(Number mostRecent) {#ariaid-title19}

Returns either the most recent journal entry or all journal entries.
{#SGE-getJournalEntry_N__table_lpt_2wp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| mostRecent | Number | If 1, returns the most recent entry. If -1, returns all journal entries. |
[Table 35. Parameters]

{#SGE-getJournalEntry_N__table_lpt_2wp_fz} {#SGE-getJournalEntry_N__table_mpt_2wp_fz__entry__2}

| 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". |
[Table 36. Returns]

{#SGE-getJournalEntry_N__table_mpt_2wp_fz}  

    //gets all journal entries as a string where each entry is delimited by '\n\n'
    var notes = current.work_notes.getJournalEntry(-1); 
    //stores each entry into an array of strings
    var na = notes.split("\n\n");  
                          
    for (var i = 0; i < na.length; i++)                 
      gs.info(na[i]);

## Scoped GlideElement - getLabel() {#ariaid-title20}

Returns the object label.
{#SGE-getLabel__table_tlw_sxp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 37. Parameters]

{#SGE-getLabel__table_tlw_sxp_fz} {#SGE-getLabel__table_ulw_sxp_fz__entry__2}

| Type | Description |
|-|-|
| String | Object label |
[Table 38. Returns]

{#SGE-getLabel__table_ulw_sxp_fz}  

    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");
        var variables = now_GR.variables.getElements();    
        for (var key in variables) {
          var now_V = variables[key];
          if(now_V.getQuestion().getLabel() != ) {
             template.space(4);
             template.print('     ' +  now_V.getQuestion().getLabel() + " = " + now_V.getDisplayValue() + "\n");  
          }
        }
    }

## Scoped GlideElement - getLabelLang(String language) {#ariaid-title21}

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](https://www.servicenow.com/docs/access?context=t_ActivateALanguage&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).  
See also:

* [getDisplayValueLang()](https://servicenow-prod.fluidtopics.net/y~_OwldB4lvmYtOvTK4Ajg#SGE-getDisplayValueLang_S "Gets the display value of the field in the language passed as a parameter.")
* [getLabel()](https://servicenow-prod.fluidtopics.net/y~_OwldB4lvmYtOvTK4Ajg#SGE-getLabel "Returns the object label.")
{#SGE-getLabelLang_S__ul_fw4_b1b_txb}
{#SGE-getLabelLang_S__id_nbn_4c5_sxb__entry__3}

| Name | Type | Description |
|-|-|-|
| language | String | Language tag conforming with IETF BCP-47. |
[Table 39. Parameters]

{#SGE-getLabelLang_S__id_nbn_4c5_sxb} {#SGE-getLabelLang_S__table_ulw_sxp_fz__entry__2}

| 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. |
[Table 40. Returns]

{#SGE-getLabelLang_S__table_ulw_sxp_fz}  
The following example shows how to get the original label text and its German translation of the Accept (UI View) title.

    var uiView = new GlideRecord("sys_ui_view");
    uiView.get("fa776f6d97700100f309124eda2975bc");

    gs.info("getLabel: " + uiView.getElement("title").getLabel());
    gs.info("getLabelLang: " + uiView.getElement("title").getLabelLang("de"));

Output:

    getLabel: Title
    getLabelLang: Titel

## Scoped GlideElement - getName() {#ariaid-title22}

Returns the name of the field.
{#SGE-getName__table_vdn_vyp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 41. Parameters]

{#SGE-getName__table_vdn_vyp_fz} {#SGE-getName__table_wdn_vyp_fz__entry__2}

| Type | Description |
|-|-|
| String | Field name. |
[Table 42. Returns]

{#SGE-getName__table_wdn_vyp_fz}  
The following example shows how to get the name and other values for each field in a
sys_user record.

    var userRec = new GlideRecord("sys_user"); // GlideRecord to sys_user table

    userRec.get("5137153cc611227c000bbd1bd8cd2005"); // Sys Id of user: Fred Luddy

    var fields = userRec.getFields();

    for (var i = 0; i < fields.size(); i++) {

        var field = fields.get(i);
        var name = field.getName(); // Name of the field
        var label = field.getLabel(); // Label of the field
        var value = field.getDisplayValue(); // Value of the field

        gs.info((Number(i) + 1) + ".\n" + "Field Label: " + label + "\n" + "Field Name: " + name + "\n" + "Field Value: " + value);

    };

Output. Results include 62 fields and have been truncated with ellipsis points (...) to save
space.

    *** Script: 1.
    Field Label: Country code
    Field Name: country
    Field Value: 
    *** Script: 2.
    Field Label: Calendar integration
    Field Name: calendar_integration
    Field Value: Outlook
    ...
    *** Script: 47.
    Field Label: First name
    Field Name: first_name
    Field Value: Fred
    ...
    *** Script: 54.
    Field Label: Last name
    Field Name: last_name
    Field Value: Luddy
    ...

## Scoped GlideElement - getReferenceTable() {#ariaid-title23}

Gets the table name for a reference element.
{#r_ScopedGlideElementGetReferenceTable__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 43. Parameters]

{#r_ScopedGlideElementGetReferenceTable__table_vy2_525_jq} {#r_ScopedGlideElementGetReferenceTable__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Table name of the reference. |
[Table 44. Returns]

{#r_ScopedGlideElementGetReferenceTable__table_qpt_3f5_jq}  

    var grINC = new GlideRecord('incident');
    grINC.query('number','INC0010041'); // record assignment group assigned to "CAB Approval"
    if (grINC.next()) { 
      // Get the table name 
      var tableName = grINC.assignment_group.getReferenceTable();
      gs.info( tableName ); 
    }

## Scoped GlideElement - getRefRecord() {#ariaid-title24}

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.  
Warning:  
If the reference element does not contain a value, it returns an empty GlideRecord object, not a NULL object.
{#r_ScopedGlideElementGetRefRecord__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 45. Parameters]

{#r_ScopedGlideElementGetRefRecord__table_vy2_525_jq} {#r_ScopedGlideElementGetRefRecord__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| GlideRecord | A GlideRecord object |
[Table 46. Returns]

{#r_ScopedGlideElementGetRefRecord__table_qpt_3f5_jq}  


    var grINC = new GlideRecord('incident'); 
    grINC.addNotNullQuery('caller_id'); 
    grINC.query(); 
    if (grINC.next()) { 

    // Get a GlideRecord object for the referenced sys_user record 
    var grUSER = grINC.caller_id.getRefRecord(); 
    if (grUSER.isValidRecord()) 
      gs.info(grUSER.getValue('name')); 

    } 

## Scoped GlideElement - getTableName() {#ariaid-title25}

Returns the name of the table on which the field resides.
{#SGE-getTableName__table_gfq_szp_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 47. Parameters]

{#SGE-getTableName__table_gfq_szp_fz} {#SGE-getTableName__table_hfq_szp_fz__entry__2}

| 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. |
[Table 48. Returns]

{#SGE-getTableName__table_hfq_szp_fz}  

    if (current.approver.getTableName() == "sysapproval_approver") {
      if (current.approver == email.from_sys_id)  {
         current.comments = "reply from: " + email.from + "\n\n" + email.body_text;
     
       // if it's been cancelled, it's cancelled.
      var doit = true;
      if (current.state=='cancelled')
          doit = false;
     
      if (email.body.state != undefined)
         current.state= email.body.state;
     
       if (doit)
          current.update();
    } else {
       gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") rejected because user sending 
               email( "+email.from+") does not match the approver ("+current.approver.getDisplayValue()+")");
    }
     
    }

## Scoped GlideElement - nil() {#ariaid-title26}

Determines if a field is null.
{#r_ScopedGlideElementNil__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 49. Parameters]

{#r_ScopedGlideElementNil__table_vy2_525_jq} {#r_ScopedGlideElementNil__table_bdf_zfr_2r__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the field is null. Possible values: * true: Field is null. * false: Field is not null. {#r_ScopedGlideElementNil__ul_lhk_bzp_krb} |
[Table 50. Returns]

{#r_ScopedGlideElementNil__table_bdf_zfr_2r}  

    var glideRecord = new GlideRecord('incident'); 
    glideRecord.query('priority','1'); 
    glideRecord.next(); 
    gs.info(glideRecord.state.nil());

Output:

    false

## Scoped GlideElement - setDateNumericValue(Number milliseconds) {#ariaid-title27}

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.  
Note:  
Before calling this method, the element must already exist by querying an existing record or by using the now_GR.initialize() method to initialize a new record.
{#SGE-setDateNumericValue_N__table_hqp_hfd_1z__entry__3}

| Name | Type | Description |
|-|-|-|
| milliseconds | Number | Number of milliseconds since 1/1/1970 |
[Table 51. Parameters]

{#SGE-setDateNumericValue_N__table_hqp_hfd_1z} {#SGE-setDateNumericValue_N__table_iqp_hfd_1z__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 52. Returns]

{#SGE-setDateNumericValue_N__table_iqp_hfd_1z}  

    var now_GR = new GlideRecord("incident");
    now_GR.initialize();
    now_GR.opened_at.setDateNumericValue(10000);

## Scoped GlideElement - setDisplayValue(Object value) {#ariaid-title28}

Sets the display value of the field.
{#r_ScopedGlideElementSetDisplayValue_Object_value__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| value | Object | The value to set for the field. |
[Table 53. Parameters]

{#r_ScopedGlideElementSetDisplayValue_Object_value__table_vy2_525_jq} {#r_ScopedGlideElementSetDisplayValue_Object_value__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 54. Returns]

{#r_ScopedGlideElementSetDisplayValue_Object_value__table_qpt_3f5_jq}  

    var glideRecord = new GlideRecord('incident'); 
    glideRecord.query('priority','1'); 
    glideRecord.next();
     
    //change the urgency to 3 
    glideRecord.urgency.setDisplayValue('3 - Low');
    gs.info(glideRecord.urgency);

## Scoped GlideElement - setError(String errorMessage) {#ariaid-title29}

Adds an error message. Available in Fuji patch 3.
{#r_ScopedGlideElementSetError_String__table_ix3_q5t_vr__entry__3}

| Name | Type | Description |
|-|-|-|
| errorMessage | String | The error message. |
[Table 55. Parameters]

{#r_ScopedGlideElementSetError_String__table_ix3_q5t_vr} {#r_ScopedGlideElementSetError_String__table_jx3_q5t_vr__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 56. Returns]

{#r_ScopedGlideElementSetError_String__table_jx3_q5t_vr}  

    var glideRecord = new GlideRecord('incident');
    glideRecord.query('priority','1');
    glideRecord.next();
     
    glideRecord.short_description.setError('Error text');

## Scoped GlideElement - setPhoneNumber(Object phoneNumber, Boolean strict) {#ariaid-title30}

Sets the field to the specified phone number.
This method is only available on a phone number GlideElement.
{#r_SGE-setPhoneNumber_O_B__table_exy_3m2_bx__entry__3}

| 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. |
[Table 57. Parameters]

{#r_SGE-setPhoneNumber_O_B__table_exy_3m2_bx} {#r_SGE-setPhoneNumber_O_B__table_fxy_3m2_bx__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the phone number value was set. Possible values: * true: Value was set. * false: Value was not set. {#r_SGE-setPhoneNumber_O_B__ul_zts_mzp_krb} |
[Table 58. Returns]

{#r_SGE-setPhoneNumber_O_B__table_fxy_3m2_bx}  
The following example shows how to set the phone number of a walk-up location. This example
requires the Walk-up Experience plugin.

    setWalkupLocPhone('Santa Clara Tech Lounge','+91 9812456789'); 

    function setWalkupLocPhone(locName, phoneNumber) {
      var walkupLoc = new GlideRecord('wu_location_queue');
      walkupLoc.addQuery('name', locName);
      walkupLoc.query();
      walkupLoc.next();
      
      // Set phone number of walk-up location
      var isPhoneNumberSet = walkupLoc.phone_number.setPhoneNumber(phoneNumber, true);
      walkupLoc.update();
      gs.info('Phone Number: ' + walkupLoc.phone_number);
      gs.info('Is phone number specified match the correct format: ' + isPhoneNumberSet);
    }

Output:

    Phone Number: +919812456789
    Is phone number specified match the correct format: true

## Scoped GlideElement - setValue(Object value) {#ariaid-title31}

Sets the value of a field.
Note:  
Before calling this method, the element must already exist by querying an existing record or by using the now_GR.initialize() method to initialize a new record.  

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.  
    See also:

    * [Deprecate GlideEncrypter usage of 3DES for password2 fields](https://www.servicenow.com/docs/access?context=password2-3des-deprecation&version=xanadu&pubname=xanadu-platform-security&ft:locale=en-US)
    * [Alternatives to GlideEncrypter usage in knowledge base article KB1320986](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1320986)
    * [Password2 encryption with the Key Management Framework (KMF)](https://www.servicenow.com/docs/access?context=password-2way-encrypted-fields&version=xanadu&pubname=xanadu-platform-security&ft:locale=en-US)
    {#r_ScopedGlideElementSetValue_Object_value__ul_m1z_5js_12c}
{#r_ScopedGlideElementSetValue_Object_value__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| value | Object | Object value to set the field to. |
[Table 59. Parameters]

{#r_ScopedGlideElementSetValue_Object_value__table_vy2_525_jq} {#r_ScopedGlideElementSetValue_Object_value__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 60. Returns]

{#r_ScopedGlideElementSetValue_Object_value__table_qpt_3f5_jq}  
Set the value passing a string.

    var glideRecord = new GlideRecord('incident');
    glideRecord.query('priority','1');
    glideRecord.next();
    glideRecord.short_description.setValue('Network failure');

Set the value passing an object.

    var now_GR  = new GlideRecord('student');
    now_GR.initialize();
    now_GR.setValue('first_name', 'Joe');
    now_GR.setValue('last_name', 'Smith');
    now_GR.insert();

## Scoped GlideElement - toString() {#ariaid-title32}

Converts the value of a GlideRecord field to a string.
{#r_ScopedGlideElementToString__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 61. Parameters]

{#r_ScopedGlideElementToString__table_vy2_525_jq} {#r_ScopedGlideElementToString__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Value as a string. |
[Table 62. Returns]

{#r_ScopedGlideElementToString__table_qpt_3f5_jq}  

    var glideRecord = new GlideRecord('incident');
    glideRecord.query('priority','1');
    glideRecord.next();
    gs.info(glideRecord.opened_at.toString());

Output:

    2019-08-31 23:09:51


