GlideElement - Global

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 80분
  • 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.

    표 1. Parameters
    Name Type Description
    None
    표 2. Returns
    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.

    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

    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.

    표 3. Parameters
    Name Type Description
    None
    표 4. Returns
    Type Description
    Boolean True if the field can be read, false otherwise.

    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 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.

    표 5. Parameters
    Name Type Description
    None
    표 6. Returns
    Type Description
    Boolean True if the user can write to the field, false otherwise.

    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 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.

    주:
    The changes() method is not supported within ACL scripts.
    주:
    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.
    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.

    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.

    표 7. Parameters
    Name Type Description
    None
    표 8. Returns
    Type Description
    Boolean True if the field has changed, false otherwise.

    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.

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

    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.

    주:
    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.
    표 9. Parameters
    Name Type Description
    value Object An object value to check against the previous value of the current field.
    표 10. Returns
    Type Description
    Boolean True if the previous value matches the parameter, false if it does not.
    if (theState.changesTo(resolvedState)) {
      operation = 4; //Resolved
    }
    else if (theState.changesTo(closedState)) {
      operation = 11; //Resolution Accepted
    }
    else if (theState.changesFrom(resolvedState) || theState.changesFrom(closedState)) {
      operation = 10; //Re-open
    }
    else {
      operation = 6; //Update
    }

    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.

    주:
    The changesTo() method is not supported within ACL scripts.
    주:
    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.
    표 11. Parameters
    Name Type Description
    value Object An object value to check against the new value of the current field.
    표 12. Returns
    Type Description
    Boolean True if the new value matches the parameter, false if it does not.
    if (theState.changesTo(resolvedState)) {
      operation = 4; //Resolved
    }
    else if (theState.changesTo(closedState)) {
      operation = 11; //Resolution Accepted
    }
    else if (theState.changesFrom(resolvedState) || theState.changesFrom(closedState)) {
      operation = 10; //Re-open
    }
    else {
      operation = 6; //Update
    }

    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.

    표 13. Parameters
    Name Type Description
    None
    표 14. Returns
    Type Description
    Number Number of milliseconds since January 1, 1970, 00:00:00 GMT.
    var inc = new GlideRecord('incident');
    inc.get('17c90efb13418700cc36b1422244b05d');
    gs.info(inc.calendar_duration.dateNumericValue());

    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).

    표 15. Parameters
    Name Type Description
    o Object An object to debug.
    표 16. Returns
    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.

    표 17. Parameters
    Name Type Description
    attributeName String Attribute name
    표 18. Returns
    Type Description
    String Attribute value
    doit();
    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"));
      }
     
    }

    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.

    표 19. Parameters
    Name Type Description
    None
    표 20. Returns
    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.

    The following example shows how to the base table for the Assignment Group field of an Incident record.

    var gr = new GlideRecord('incident');
    
    //query the Incident Records which have category as Inquiry/Help
    gr.addQuery('category','inquiry');
    
    // sort them in the order of earlier to recent created date
    gr.orderBy('sys_created_on');
    gr.query();
    
    if(gr.next()){ //If at least any one record exists matching this query
    
      //Print the base table for the Assignment Group field
      gs.print("The Base Table for the field Assignment Group is - " + gr.assignment_group.getBaseTableName()); 
    };

    Output:

    The Base Table for the field Assignment Group is - task

    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).

    표 21. Parameters
    Name Type Description
    attributeName String Attribute name
    표 22. Returns
    Type Description
    Boolean Boolean value of the attribute. Returns false if the attribute does not exist.

    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 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.

    표 23. Parameters
    Name Type Description
    dependent String Optional. Field within the associated record on which the choice list field depends.
    표 24. Returns
    Type Description
    array list The choice values for the field.
    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 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.

    표 25. Parameters
    Name Type Description
    None
    표 26. Returns
    Type Description
    String The choice label.

    The following example shows how to get the choice label for change request records with the a priority value of Normal.

    var gr = new GlideRecord('change_request');
    
    //query for the change records with change type as "Normal"
    gr.addQuery('type','normal');
    
    // sort them in the order of recent to earlier Created Date
    gr.orderByDesc('sys_created_on'); 
    
    // limit the query to 4 records
    gr.setLimit(4); 
    gr.query();
    
    while(gr.next()){
     //Printing the choice label for those records
     gs.print("The label of the current priority '"+ gr.priority+"' for the change request - " + gr.number + " is - "+ gr.priority.getChoiceValue()); 
    }

    Output:

    The label of the current priority '4' for the change request - CHG0000014 is - 4 - Low
    The label of the current priority '4' for the change request - CHG0000013 is - 4 - Low
    The label of the current priority '4' for the change request - CHG0000012 is - 4 - Low
    The label of the current priority '4' for the change request - CHG0000011 is - 4 - Low

    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().

    표 27. Parameters
    Name Type Description
    None
    표 28. Returns
    Type Description
    Number The number of debug messages.

    GlideElement - getDependent()

    Returns the field (element) that a specified field is dependent on.

    표 29. Parameters
    Name Type Description
    None
    표 30. Returns
    Type Description
    String Name of the field on which the current field depends. Null if no dependencies.

    The following example shows how to find the parent field of the Configuration Item field using the getDependent() method.

    var inc_gr = new GlideRecord('incident');
    inc_gr.get('985f53d82fab301032e8808cf699b6e8'); // Get a particular Incident
    
    var field_element = inc_gr.getElement('cmdb_ci'); // Get the Configuration Item element
    var dependent_field = field_element.getDependent(); // Read the dependent field
    gs.info("Dependent field: " + dependent_field);
    if(dependent_field)
      {
        var dependent_field_value = inc_gr.getValue(dependent_field);  
        if(!dependent_field_value)
          {
            var base_table = field_element.getRefRecord(); // Retrieve the reference record
            var dependent_field_value = base_table.getValue(dependent_field); // Read the parent field value
          }
        inc_gr.setValue(dependent_field, dependent_field_value); // Update the parent field on the Incident
        inc_gr.update();
      }

    Output:

    company

    GlideElement - getDependentTable()

    Gets the table that the current table depends on.

    표 31. Parameters
    Name Type Description
    None
    표 32. Returns
    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.

    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.
    표 33. Parameters
    Name Type Description
    maxChar Number Optional. Maximum number of characters to return.
    표 34. Returns
    Type Description
    String Display value of the field.
    var fields = current.getFields();
    for (var i = 0; i < fields.size(); i++) { 
      var field = fields.get(i);
      var name = field.getName(); 
      var value = field.getDisplayValue(); 
      gs.print(i + ". " + name + "=" + value); 
    }

    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.

    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.
    표 35. Parameters
    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.
    표 36. Returns
    Type Description
    String Formatted display value of the field, or the specified substitute value.

    The following example shows how to display the two most recent active records in the Incident [incident] table.

    var gr = new GlideRecord('incident');
    gr.addQuery('active', true);      // get the active records
    gr.orderByDesc('sys_updated_on'); // sort the records from most recent to oldest updated date
    gr.setLimit(2);                   // limit the query to 2 records
    gr.query();
    
    while(gr.next()){ // Printing the Display Value of the Configuration Item field. 
      // If the Display Value is Null/Empty, then it will be substituted with Default value "I with Null/Empty Display Value"
      gs.info("The Display Value of the Configuration Item for the incident - "+ gr.number+ " is " + gr.cmdb_ci.getDisplayValueExt(40, " CI with Null/Empty Display Value"));
    }

    Output:

    The Display Value of the Configuration Item for the incident - INC0007001 is  CI with Null/Empty Display Value
    The Display Value of the Configuration Item for the incident - INC0000069 is NYC RAC

    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).

    표 37. Parameters
    Name Type Description
    language String Language tag conforming with IETF BCP-47.
    표 38. Returns
    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.

    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 equivalent

    To use the getDisplayValueLang() method in a scoped application, use the corresponding scoped method: getDisplayValueLang().

    GlideElement - getDynamicAttribute()

    Returns a dynamic attribute definition for this GlideElement.

    표 39. Parameters
    Name Type Description
    None
    표 40. Returns
    Type Description
    IDynamicAttribute Object describing the attribute that the GlideElement represents.

    GlideElement - getDynamicNamespace()

    Returns a dynamic namespace object that is configured for the GlideElement.

    표 41. Parameters
    Name Type Description
    None
    표 42. Returns
    Type Description
    IDynamicNamespace Object describing the dynamic namespace.

    The following code example shows how to call this method.

    //Gets the namespace object configured for the inc_dynamic_schema dynamic_attribute_store column on the incident table
     
    var gr_Inc = new GlideRecord('incident');
    gr_Inc.query();
    if (gr_Inc.next()) {
        var ge_Make = gr_Inc.getElement('inc_dynamic_schema->make');
        var namespace = ge_Make.getDynamicNamespace();
     
        gs.info("toString:    " + namespace);
        gs.info("name:        " + namespace.getName());
        gs.info("isActive:    " + namespace.isActive());
        gs.info("isTransient: " + namespace.isTransient());
    }

    Output:

    toString:    incident/inc_dynamic_schema
    name:        incident/inc_dynamic_schema
    isActive:    true
    isTransient: false

    GlideElement - getDynamicNamespaceName()

    Gets the name of the dynamic namespace configured for the GlideElement.

    표 43. Parameters
    Name Type Description
    None
    표 44. Returns
    Type Description
    String Name of the dynamic namespace.

    The following example shows how to return the dynamic attribute namespace name.

    // Gets the name of the namespace from the inc_dynamic_schema dynamic_attribute_store column on the incident table
     
    var gr_Inc = new GlideRecord('incident');
    gr_Inc.query();
    if (gr_Inc.next()) {
        var ge_Make = gr_Inc.getElement('inc_dynamic_schema->make');
        gs.info(ge_Make.getDynamicNamespaceName());
    }

    Output:

    number,short_description,active

    GlideElement - getED()

    Returns an element descriptor, which provides information about specific fields, rather than the data inside of those fields.

    표 45. Parameters
    Name Type Description
    None
    표 46. Returns
    Type Description
    ElementDescriptor The field's element descriptor.

    This example gets the fields and field descriptors for the current record.

    var fields = current.getFields();
    for (i=0; i<fields.size(); i++) { 
      var field = fields.get(i);
      var descriptor = field.getED(); 
      gs.print("type=" + descriptor.getType() + 
        " internalType=" + descriptor.getInternalType()); 
    }

    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.

    표 47. Parameters
    Name Type Description
    value String Element whose value you want returned.
    표 48. Returns
    Type Description
    String Value of the element.
    var fields = current.getFields();
    for (var i = 0; i < fields.size(); i++) {
      var field = fields.get(i);
      var name = field.getName();
    
      // Returns the unformatted value of the element
      var value = field.getElementValue(name);
      var disValue = field.getDisplayValue();
      gs.print(i + ". " + name + " = " + value + ' display value = ' + disValue);
    }

    Output

    1. cmdb_ci = 109562a3c611227500a7b7ff98cc0dc7 display value = Storage Area Network 001
    2. impact = 2 display value = 2 - Medium

    GlideElement - getError()

    Returns any error message associated with the specified element.

    Use the setError() method to set an error on a specific field (element).

    표 49. Parameters
    Name Type Description
    None
    표 50. Returns
    Type Description
    String Error message currently set for the specified element.

    This example shows how to set an error on the short_description element and then read the error back.

    var incidentGR = new GlideRecord('incident');
    incidentGR.setLimit(1);
    incidentGR.query();
    if (incidentGR.next()) {
        incidentGR.short_description.setError('The description is too short.');
        gs.info(incidentGR.short_description.getError()); // 'The description is too short.'
    }

    Output:

    The description is too short.

    This example shows how to use getError() in a function call.

    // Before query business rule (order = 100)
    (function executeRule(current, previous /*null when async*/) {
        var shortDescription = current.getValue('short_description');
        if (shortDescription.length < 10) {
            current.short_description.setError('The description is too short.');
            current.setAbortAction(true);
        }
    })(current, previous);
    
    // Before query business rule (order = 200)
    (function executeRule(current, previous /*null when async*/) {
        var shortDescriptionErrMsg = current.short_description.getError();
        if (shortDescriptionErrMsg) {
            // Some error was set in one of the previous business rules.
        }
    })(current, previous);

    GlideElement - getEscapedValue()

    Gets the escaped value for the current element.

    표 51. Parameters
    Name Type Description
    None
    표 52. Returns
    Type Description
    String The escaped value of the current element.

    The following example shows how to use the getEscapedValue() method to display the contents of an Incident short description field with escape characters.

    /*** Overview - Update incident short description with escape characters and printing ***/
    var inc = new GlideRecord('incident');
    inc.query();
    inc.next();
    inc.short_description = 'Can\'t log into SAP from my laptop today'; 
    inc.update();
    gs.info("Short Description: "+inc.getElement('short_description').toString()); //without escape characters
    gs.info("Escaped Short Description: "+inc.getElement('short_description').getEscapedValue()); // with escape characters

    Output:

    Short Description: Can't log into SAP from my laptop today
    Escaped Short Description: Can\'t log into SAP from my laptop today

    GlideElement - getFieldStyle()

    Gets the CSS style for the field.

    표 53. Parameters
    Name Type Description
    None
    표 54. Returns
    Type Description
    String The CSS style for the field.
    var fields = current.getFields();
    for (var i = 0; i < fields.size(); i++) { 
      var field = fields.get(i);
      var css_style = field.getFieldStyle();  
      gs.print("CSS style" + "=" + css_style); 
    }

    GlideElement - getGlideObject()

    Gets a glide object.

    표 55. Parameters
    Name Type Description
    None
    표 56. Returns
    Type Description
    Object A Glide object.
    function calcDateDelta(start, end, calendar) {
      var cal = GlideCalendar.getCalendar(calendar);
      if (!cal.isValid())
          return null;
      var realStart = start.getGlideObject();
      var realEnd = end.getGlideObject();  
      var duration = cal.subtract(realStart, realEnd);
      return duration;
    }

    GlideElement - getGlideRecord()

    Gets a glide record.

    표 57. Parameters
    Name Type Description
    None
    표 58. Returns
    Type Description
    GlideRecord A glide record object.
    var grInc = new GlideRecord('incident');
    grInc.get('sys_id','ef43c6d40a0a0b5700c77f9bf387afe3');
    gs.info("Initial grInc - " + grInc.getDisplayValue());
    
    var caller = grInc.getElement("caller_id");
    doit(caller);
    
    function doit(caller) {
      var now_GR = caller.getGlideRecord();
      gs.info("doit gr is - " + now_GR.getDisplayValue());
    }

    Output

    *** Script: Initial grInc - INC0000050
    *** Script: doit gr is - INC0000050

    GlideElement - getHTMLValue(Number maxChars)

    Returns the HTML value of a field.

    표 59. Parameters
    Name Type Description
    maxChars Number Optional. Maximum number of characters to return.
    표 60. Returns
    Type Description
    String HTML value for the field.

    The following example shows how to get the HTML content of a meeting note.

    /*
      getHTMLValueExt() This Function is used to get HTML Value of a field. It accepts 2 Parameters
    
    a. maxChar- Number - The maximum number of characters to return.
    b. nullSub - String - The value to return if the HTML value is null or empty.
    
    */
    
    
    // get a cab meeting record by its sys_id
    var gr = new GlideRecord('cab_meeting');
    gr.addQuery('sys_id','7777777b6d2a20100sys70id534330f6');
    gr.query();
    
    if(gr.next()){
      var substituteString = 'Meeting Notes Unavailable';
      var maxLength = 50;
      gs.print(gr.meeting_notes.getHTMLValueExt(maxLength, substituteString));
    }

    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.

    표 61. Parameters
    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.
    표 62. Returns
    Type Description
    String The HTML value or the specified substitute value.

    The following example shows how to get the HTML content of a meeting note.

    // get a cab meeting record by its sys_id
    var gr = new GlideRecord('cab_meeting');
    gr.addQuery('sys_id','7777777b6d2a20100sys70id534330f6');
    gr.query();
    
    if(gr.next()){
      var substituteString = 'Meeting Notes Unavailable';
      var maxLength = 50;
      gs.print(gr.meeting_notes.getHTMLValueExt(maxLength, substituteString));
    }
    Output if the meeting note for the record selected is not empty:
    <p>Meeting note content.</p>

    GlideElement - getJournalEntry(Number mostRecent)

    Returns either the most recent journal entry or all journal entries.

    표 63. Parameters
    Name Type Description
    mostRecent Number If 1, returns the most recent entry. If -1, returns all journal entries.
    표 64. Returns
    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".

    //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.print(na[i]);

    Scoped equivalent

    To use the getJournalEntry() method in a scoped application, use the corresponding scoped method: getJournalEntry().

    GlideElement - getLabel()

    Returns the object's label.

    표 65. Parameters
    Name Type Description
    None
    표 66. Returns
    Type Description
    String Object's label
    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 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.

    표 67. Parameters
    Name Type Description
    language String Language tag conforming with IETF BCP-47.
    표 68. Returns
    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.

    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 equivalent

    To use the getLabelLang() method in a scoped application, use the corresponding scoped method: getLabelLang().

    GlideElement - getName()

    Returns the name of the field.

    표 69. Parameters
    Name Type Description
    None
    표 70. Returns
    Type Description
    String Field name.

    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 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.

    경고:
    If the reference element does not contain a value, it returns an empty GlideRecord object, not a NULL object.
    표 71. Parameters
    Name Type Description
    None
    표 72. Returns
    Type Description
    GlideRecord A GlideRecord object
    
    var grINC = new GlideRecord('incident'); 
    grINC.notNullQuery('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.print( grUSER.getValue('name') ); 
    
    } 

    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.

    표 73. Parameters
    Name Type Description
    None
    표 74. Returns
    Type Description
    String The CSS style for the value.
    // Get string of style field from Field Style record
    var cssStyle = now_GR.state.getStyle();

    GlideElement - getTableName()

    Returns the name of the field's table.

    표 75. Parameters
    Name Type Description
    None
    표 76. Returns
    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.
    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 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.

    표 77. Parameters
    Name Type Description
    None
    표 78. Returns
    Type Description
    String Escaped display value HTML for the associated field.

    The following example retrieves the display value of a KB article.

    var grh = new GlideRecord('kb_knowledge');
    grh.get('c85cd2519f77230088aebde8132e70c2');  // Knowledge record sys_id
    var t = grh.text.getTextAreaDisplayValue(); // Text is HTML type field
    var d = GlideXMLUtil.parseHTML(t); // Parse the HTML
    var b = d.getDocumentElement().getTextContent().trim();
    gs.info(b);

    Output:

    This article explains how to use automatic replies in Outlook 2010 for Exchange accounts.
    
    Setting Up Automatic Replies
    
    Click the 
    File tab.
    Click 
    Automatic Replies.
    Select 
    Send automatic replies.
    If desired, select the 
    Only send during this time range check box to schedule when your out of office replies are active. If you do not specify a start and end time, auto-replies will be sent until you select the
     Do not send automatic replies check box.
    On the 
    Inside My Organization tab, type the response that you want to send to colleagues while you are out of the office.
    On the 
    Outside My Organization tab, select the 
    Auto-reply to people outside my organization check box, and then type the response that you want to send while you are out of the office. Select whether you want replies sent to 
    My contacts only or to 
    Anyone outside my organization who sends you messages.
    
    NOTE:
    If you select 
    My Contacts only in step 6, replies will be sent 
    only to contacts that exist in your Contacts folder.
    
    
    
    Using Rules With Automatic Replies
    It is also possible to use rules to manage your messages while you are out of office. For example, you can create rules to automatically move or copy messages to other folders, to delete messages, to send custom replies, and so on.
    
    Click the 
    File tab.
    Click 
    Automatic Replies.
    Click 
    Rules, and then click 
    Add Rule.
    Under 
    When a message arrives that meets the following conditions, specify the conditions that the message must meet for the rule to be applied. If you want to specify more conditions, click 
    Advanced, enter or select the options that you want, and then click 
    OK.
    If you want to specify that this rule must be applied last, select the 
    Do not process subsequent rules check box.
    Under 
    Perform these actions, select the actions that you want. You can select more than one action.
    Click 
    OK three times.
    
    NOTES:
    
    Automatic Replies rules can also be edited by following the above procedure.
    To turn Automatic Replies rules on or off, in the Automatic Reply Rules dialog box, select or clear the check box of the rule that you want to turn on or off.
    

    GlideElement - getValue()

    Returns the value of the field in the database.

    표 79. Parameters
    Name Type Description
    None
    표 80. Returns
    Type Description
    String The value of the field.

    The following example retrieves the value of a specified field in the 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
    

    GlideElement - getXHTMLValue()

    Retrieves the XHTML value of a field.

    표 81. Parameters
    Name Type Description
    None
    표 82. Returns
    Type Description
    String The XHTML value

    GlideElement - getXMLValue()

    Gets the XML value of a field as a string.

    표 83. Parameters
    Name Type Description
    None
    표 84. Returns
    Type Description
    String The XML value

    GlideElement - hasAttribute(String attributeName)

    Determines whether a field has a particular attribute.

    표 85. Parameters
    Name Type Description
    attributeName String The attribute to check for
    표 86. Returns
    Type Description
    Boolean True if the field has the attribute, false otherwise.
    var totalCritical = 0;
     
    var filledCritical = 0; var fields = current.getFields(); gs.print(fields); for (var num = 0; num &lt; fields.size(); num++) { 
     
        gs.print("RUNNING ARRAY VALUE " + num);
       var ed = fields.get(num).getED();
       if(ed.hasAttribute("tiaa_critical")) {
           gs.print("CRITICAL FIELD FOUND");
           totalCritical ++;
           if (!fields.get(num).isNil()) {
               filledCritical ++;
           }
       }
     
    } var answer = 0; gs.print("TOTAL - " + totalCritical); gs.print("FILLED - " + filledCritical); if (filledCritical &gt; 0 &amp;&amp; totalCritical &gt; 0){ 
     
        var pcnt = (filledCritical/totalCritical)*100;
       answer = pcnt.toFixed(2);;    
     
    } answer;

    GlideElement - hasRightsTo(String operationName)

    Determines if the user has the right to perform a particular operation.

    표 87. Parameters
    Name Type Description
    operationName String Name of the operation to check for
    표 88. Returns
    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:
    • true: User has permissions.
    • false: User does not have permissions.

    The following example shows how to determine if a user has rights to read a specific table.

    // Pass table name and userId to check if user has read access against given table name
    checkAccess('incident', 'adela.cervantsz');
    
    function checkAccess(tableName, userID) {
    
        var inc = new GlideRecordSecure(tableName);
        inc.get('$[sys_id]');
    
        var secureManager = GlideSecurityManager.get();
    
        //fetch a different user, using user_name field on the target user record
        var userObj = gs.getUser().getUserByID(userID); 
        secureManager.setUser(userObj);
    
        var access = 'record/incident/read';
    
        //check if user has right to access
        var canRead = secureManager.hasRightsTo(access, inc); 
        gs.info('canRead: ' + canRead);
    }

    Output:

    canRead: false

    GlideElement - hasValue()

    Determines if the field has a value.

    표 89. Parameters
    Name Type Description
    None
    표 90. Returns
    Type Description
    Boolean True if the field has a value, false otherwise.

    GlideElement - nil()

    Determines whether the field is null.

    표 91. Parameters
    Name Type Description
    None
    표 92. Returns
    Type Description
    Boolean True if the field is null or an empty string, false otherwise.
    if (current.start_date.changes() || current.end_date.changes() || current.assigned_to.changes()) { 
      if (!current.start_date.nil() && !current.end_date.nil() && !current.assigned_to.nil()) {
     gs.eventQueue("change.calendar.notify", current, current.assigned_to, previous.assigned_to);
     
    }

    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.

    표 93. Parameters
    Name Type Description
    milliseconds Number Number of milliseconds spanned by the duration.
    표 94. Returns
    Type Description
    void
    var inc = new GlideRecord('incident');
    inc.get('17c90efb13418700cc36b1422244b05d');
    var timems = inc.calendar_duration.dateNumericValue();
    timems = timems + 11*1000; 
    inc.calendar_duration.setDateNumericValue(timems)
    gs.info(inc.calendar_duration.getValue());

    Output:

    1970-01-01 00:01:38

    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.

    표 95. Parameters
    Name Type Description
    displayValue Object Value to be displayed.
    표 96. Returns
    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.

    표 97. Parameters
    Name Type Description
    None
    표 98. Returns
    Type Description
    None
    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.setAbortAction(true);
        current.u_date1.setError('start must be before end');
      }
    }

    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.

    표 99. Parameters
    Name Type Description
    value Object Initial value for the field.
    표 100. Returns
    Type Description
    void

    GlideElement - setJournalEntry(String entry, String userName)

    Adds a journal entry and author as a work note or comment field.

    표 101. Parameters
    Name Type Description
    entry String Content of the journal entry.
    userName String Optional. The user to attribute the journal entry to.
    표 102. Returns
    Type Description
    None

    The following example shows how to add a work note and its author to a record.

    var now_GR = new GlideRecord("incident");
    
    now_GR.addQuery("sys_id", "<sys_id_value>");
    now_GR.query();
    
    if(now_GR.next()){
      now_GR.work_notes.setJournalEntry("Content of the journal entry.", "abel.tuter");  
      now_GR.update();
    }

    GlideElement - setValue(Object value)

    Sets the value of a field.

    주:
    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.

    표 103. Parameters
    Name Type Description
    value Object The value the field is to be set to.
    표 104. Returns
    Type Description
    None

    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 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.

    표 105. Parameters
    Name Type Description
    None
    표 106. Returns
    Type Description
    String The field's value as a string.
    doit();
     
    function doit() { 
     
      var now_GR = new GlideRecord('sys_user');
      now_GR.query();
      while (now_GR.next()) {
      if ((now_GR().length != now_GR.first_name.toString().trim().length) || (now_GR.last_name.toString().length 
             != now_GR.last_name.toString().trim().length)) {
          now_GR.first_name = now_GR.first_name.toString().trim();
          now_GR.last_name = now_GR.last_name.toString().trim();
          now_GR.autoSysFields(false);
          now_GR.update();
        }
      }
     
    }

    Scoped equivalent

    To use the toString() method in a scoped application, use the corresponding scoped method: toString().