The GlideList2 API provides methods to customize (v2) lists.

The variable g_list is used to access a specified list object. The g_list variable is not available to the related lists form link UI action. It is available to the lists form link UI action.

These methods are used in UI context menus and UI actions.

Several of these methods are available in Next Experience UI Framework. For details, see GlideList (Next Experience UI Framework).

GlideList2 - addFilter(String filter)

Adds a single term to the list query filter.

Table 1. Parameters
Name Type Description
filter String Encoded query string in standard Glide format. See Encoded query strings.
Table 2. Returns
Type Description
void

Example

g_list.addFilter("active=true");

GlideList2 - get(Object DOMelement)

Returns the GlideList2 object for the list that contains the specified item.

Table 3. Parameters
Name Type Description
DOMelement Object The DOM element ID for the list for which you want the GlideList2 object.
Table 4. Returns
Type Description
Object The GlideList2 object or null if not found.

GlideList2 - get(String ListID)

Returns the GlideList2 object for the list specified.

Table 5. Parameters
Name Type Description
ListID String The list ID for which you want the GlideList2 object.
Table 6. Returns
Type Description
Object The GlideList2 object or null if not found.

Example

function assignLabelActionViaLookupModal(tableName, listId) {
	var list = GlideList2.get(listId);
	if (!list)
		return;

	assignLabelViaLookup(tableName, sysIds, list.getView());
}

GlideList2 - getChecked()

Returns a comma-separated list of the sys_ids for the items that are checked in the associated list.

Table 7. Parameters
Name Type Description
none
Table 8. Returns
Type Description
String Comma-separated list of the sys_ids for the items that are checked in the list. Does not check to determine that the items returned are allowed to be executed.

Example

function removeLabelActionViaLookupModal(tableName, listId) {
  var list = GlideList2.get(listId);
  if (!list)
    return;

  var sysIds = list.getChecked();
  if (!sysIds)
    return;

  removeLabelViaLookup(tableName, sysIds);
}

GlideList2 - getFixedQuery()

Returns the fixed query.

A fixed query is the part of the query that cannot be removed from the breadcrumb (i.e., it is fixed for the user). It is specified by including a sysparm_fixed_query parameter for the application module.

Table 9. Parameters
Name Type Description
none
Table 10. Returns
Type Description
String The fixed query string for the list.

Example

var list = GlideList2.get(container.readAttribute('list_id'));
var filter = this._getFilter(element);
var fixedQuery = list.getFixedQuery();
if (fixedQuery)
  filter = fixedQuery + "^" + filter;

GlideList2 - getGroupBy()

Returns the field or comma-separated list of fields that are used to group the list.

Table 11. Parameters
Name Type Description
none
Table 12. Returns
Type Description
String The field or comma-separated list of fields that are used to group the list.

Example

function runFilterV2Lists(name, filter) {
  var list = GlideList2.get(name);	
    if (list) {
      var groupBy = list.getGroupBy();
      if (groupBy)  
        filter += "^" + groupBy;
		
        list.setFilterAndRefresh(filter);
    }
}

GlideList2 - getListName()

Returns the name of the list, which is usually the table name.

Table 13. Parameters
Name Type Description
none
Table 14. Returns
Type Description
String The list name (usually the table name).

Example

var list = GlideList2.get(name);	
var listName = list.getListName();

GlideList2 - getOrderBy()

Returns the first field used to order the list.

Table 15. Parameters
Name Type Description
none
Table 16. Returns
Type Description
String The field by which to order the list. Empty if the list is not ordered.

Example

var list = GlideList2.get(listId);
if (!list)
  return;
var orderBy = list.getOrderBy();

GlideList2 - getParentTable()

Returns the name of the parent table for a related list (the table associated with the form).

Table 17. Parameters
Name Type Description
none
Table 18. Returns
Type Description
String The parent table name.

Example

for (var id in GlideLists2) {
  var list = GlideLists2[id];
  if (list.getTableName() == listTableName && list.getParentTable() == tableName)
    return list.getContainer();
}

GlideList2 - getQuery(Boolean orderBy, Boolean groupBy, Boolean fixed, Boolean all)

Returns the encoded query string for the list.

Table 20. Returns
Type Description
String Encoded query string for the list.

Example

var list = GlideList2.get(this.listID);
var ajax = new GlideAjax("AJAXJellyRunner", "AJAXJellyRunner.do");
  ajax.addParam("sysparm_query_encoded", list.getQuery({groupby: true, orderby: true}));
  ajax.addParam("sysparm_table", list.getTableName());
  ajax.addParam("sysparm_view", list.getView());

GlideList2 - getRelated()

Returns the related list field that associates the related list to the parent form.

Table 21. Parameters
Name Type Description
none
Table 22. Returns
Type Description
String Field that connects the list to the parent form.

Example

var list = GlideList2.get(name);
var related = list.getRelated();
if (related) 
  ajax.addParam("sysparm_is_related_list", "true");

GlideList2 - getTableName()

Returns the table name for the list.

Table 23. Parameters
Name Type Description
none
Table 24. Returns
Type Description
String Returns the table name for the list.

Example

GlideList2.getListsForTable = function(table) {
    var lists = [];
    for (var id in GlideLists2) {
        var list = GlideLists2[id];
        if (list.getTableName() == table)
            lists.push(list);
    }
    return lists;
}

GlideList2 - getView()

Returns the view used to display the list.

Table 25. Parameters
Name Type Description
none
Table 26. Returns
Type Description
String The name of the view.

Example

function assignLabelActionViaLookupModal(tableName, listId) {
	var list = GlideList2.get(listId);
	if (!list)
		return;

	assignLabelViaLookup(tableName, sysIds, list.getView());
}

GlideList2 - getTitle()

Returns the list title.

Table 27. Parameters
Name Type Description
none
Table 28. Returns
Type Description
String The list title.

Example

var list = GlideList2.get(name);	
var listTitle = list.getTitle();

GlideList2 - isUserList()

Returns true if the list has been personalized by the user by choosing the list mechanic and changing the list layout.

Table 29. Parameters
Name Type Description
none
Table 30. Returns
Type Description
Boolean True if the list layout has been changed.

Example

var list = GlideList2.get(listId);
if (!list)
  return;
if (list.isUserList())
  var tableName = list.getTableName();

GlideList2 - refresh(Number firstRow, String additionalParms)

Refreshes the list. The orderBy part of the list filter is ignored so that the list uses its natural ordering when it is refreshed.

Table 31. Parameters
Name Type Description
firstRow Number The first row to appear in the list.

Default: First row of the current view.

additionalParms String Optional name-value pairs that are submitted with the list refresh request.
Table 32. Returns
Type Description
void

Example

$timeout(function() {
  if (GlideList.lists) {
    var list = GlideList.get(name);
    if (list) {
       if (sortBy) {
         if (sortDirection == 'ASC')
            list.sort(sortBy);
         else
            list.sortDescending(sortBy);
         }  
       list.refresh();
     }
   }
}			

GlideList2 - refreshWithOrderBy(Number firstRow, String description)

Refreshes the list. The orderBy part of the list filter is included if it is specified for the list.

Table 33. Parameters
Name Type Description
firstRow Number The first row to appear in the list.

Default: First row of the current view.

description String Optional name-value pairs that are submitted with the list refresh request.
Table 34. Returns
Type Description
void

Example

ga.getXML(function(serverResponse) {
  var response = serverResponse.responseXML.getElementsByTagName("response")[0];
  if (response) {
    var list = GlideList2.getByName("backlog_stories");
    list.refreshWithOrderBy();
    var status = response.getAttribute('status');
    $j('html, body').animate({scrollTop: $j("#"+data.record.sys_id).offset().top},500);
    if (status == 'failure') {
      alert('${gs.getMessage("Story cannot be created. Team is not associated with any project.")}');
    }
  }
}

GlideList2 - setFilter(String filter)

Sets the encoded query string for the list, ignoring the orderBy and groupBy parts of the query string.

Table 35. Parameters
Name Type Description
filter String Encoded query string in standard Glide format. See Encoded query strings.
Table 36. Returns
Type Description
void

Example

list = GlideList2.get($(side+"ContentDivRelease").select(".list_div")[0].getAttribute("id"));
if (list) {
  list.setFilter("active=true");
  list.refresh(1);
 }

GlideList2 - setFilterAndRefresh(String filter)

Sets the encoded query string for the list, including the orderBy and groupBy if specified, and then refreshes the list using the new filter.

Table 37. Parameters
Name Type Description
filter String Encoded query string.
Table 38. Returns
Type Description
void

Example

function updateListFilter(projectID) {
  var list = GlideList2.getByName("backlog_stories");
  var fixedQuery = $('hdn_additional_filters').value;
  if(!projectID) {
      list.setFilterAndRefresh(fixedQuery + "^ORDERBYteam_index");
      list.setOrderBy("team_index");
  }
}

GlideList2 - setFirstRow(Number rowNum)

Sets the first row that appears in the list when the list is refreshed.

Table 39. Parameters
Name Type Description
rowNum Number Row number of the first row to display.
Table 40. Returns
Type Description
void

Example

var nextRow = 0;
var rowsPerPage = 20;
var list = GlideList2.get(listId);
if (!list)
  return;
list.setFirstRow(nextRow);
nextRow = nextRow + rowsPerPage;

GlideList2 - setGroupBy(String groupBy)

Sets the list groupBy criteria for a single field.

Table 41. Parameters
Name Type Description
groupBy String The groupBy criteria for the list.
Table 42. Returns
Type Description
void

Example

function runContextAction(listId) {
  var g_list = GlideList2.get(listId);
  g_list.setGroupBy('');
  g_list.refresh(1);
}

GlideList2 - setOrderBy(String orderBy)

Sets the orderBy criteria for the list.

For a single order by field, use orderBy field or orderByDesc field. For multiple fields, use orderByField1^orderByField2^orderByField3. orderBy specifies ascending order and orderByDesc specifies descending. These prefix strings are optional. If not specified, orderBy is the default order.

Table 43. Parameters
Name Type Description
orderBy String Single or multiple orderBy fields.
Table 44. Returns
Type Description
void

Example

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            updateOrderBy: function(orderBy){
  var list = GlideList2.get(this.listID);
  if (list)
    list.setOrderBy(orderBy);
};

GlideList2 - setRowsPerPage(Number rows)

Sets the number of rows per page to display.

Table 45. Parameters
Name Type Description
rows Number The number of rows to display.
Table 46. Returns
Type Description
void

Example

link: function(scope) {
  var list = GlideList2.get(scope.listId);
  list.setRowsPerPage(scope.maxRows);
  list.setFilterAndRefresh(scope.tableQuery);
}

GlideList2 - showHideGroups(Boolean showFlag)

Shows or hides all the groups within the list and saves the current collapsed/expanded state of the groups as a user preference.

Table 47. Parameters
Name Type Description
showFlag Boolean If true, shows the groups within the list.
Table 48. Returns
Type Description
void

Example

function showHideAllGroups(showFlag) {
  var list = GlideList2.get(listId);
  if (!list)
    return;
  list.showHideGroups(showFlag);
}

GlideList2 - showHideList(Boolean showFlag)

Displays or hides the list and saves the current collapsed/expanded state of the list as a user preference.

Table 49. Parameters
Name Type Description
showFlag Boolean If true, displays the list.
Table 50. Returns
Type Description
void

Example

GlideList2.toggleAll = function(expandFlag) {
for (var id in GlideLists2) {
  var list = GlideLists2[id];
list.showHideList(expandFlag);
}

GlideList2 - sort(String field)

Sorts the list in ascending order and sets the field as an orderBy column.

Table 51. Parameters
Name Type Description
field String Field to use to sort the list.
Table 52. Returns
Type Description
void

Example

$timeout(function() {
  if (GlideList.lists) {
    var list = GlideList.get(name);
    if (list) {
       if (sortBy) {
         if (sortDirection == 'ASC')
            list.sort(sortBy);
         else
            list.sortDescending(sortBy);
         }  
       list.refresh();
     }
   }
}

GlideList2 - sortDescending(String field, Number amount)

Sorts a single field in the list in descending order and sets the field as an orderByDescField column.

Table 53. Parameters
Name Type Description
field String Field to use to sort the list.
Table 54. Returns
Type Description
void

Example

$timeout(function() {
  if (GlideList.lists) {
    var list = GlideList.get(name);
    if (list) {
       if (sortBy) {
         if (sortDirection == 'ASC')
            list.sort(sortBy);
         else
            list.sortDescending(sortBy);
         }  
       list.refresh();
     }
   }
}

GlideList2 - toggleList()

Toggles the display of the list and saves the current collapsed/expanded state of the list as a user preference.

Table 55. Parameters
Name Type Description
none
Table 56. Returns
Type Description
void

Example

var list = GlideList2.get(listId);
if (!list)
  return;
list.toggleList();

GlideList2 - toggleListNoPref()

Toggles the display of the list but does not save the current collapsed/expanded state of the list as a user preference.

Table 57. Parameters
Name Type Description
none
Table 58. Returns
Type Description
void

Example

var list = GlideList2.get(listId);
if (!list)
  return;
list.toggleListNoPref();