{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":185,"path":"api-reference/c_GlideList2API.md","title":"GlideList2 \\(g\\_list\\) - Client","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideList2 \\(g\\_list\\)- Client\n\nThe GlideList2 API provides methods to customize \\(v2\\) lists.\n\nThe 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.\n\nThese methods are used in UI context menus and UI actions.\n\nSeveral of these methods are available in Next Experience UI Framework. For details, see [GlideList \\(Next Experience UI Framework\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/GlideListClientAPINEx.md).\n\n**Parent Topic:**[Client API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/api-client.md)\n\n## GlideList2 - addFilter\\(String filter\\)\n\nAdds a single term to the list query filter.\n\n|Name|Type|Description|\n|----|----|-----------|\n|filter|String|Encoded query string in standard Glide format. See [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\ng_list.addFilter(\"active=true\");\n```\n\n## GlideList2 - get\\(Object DOMelement\\)\n\nReturns the GlideList2 object for the list that contains the specified item.\n\n|Name|Type|Description|\n|----|----|-----------|\n|DOMelement|Object|The DOM element ID for the list for which you want the GlideList2 object.|\n\n|Type|Description|\n|----|-----------|\n|Object|The GlideList2 object or null if not found.|\n\n## GlideList2 - get\\(String ListID\\)\n\nReturns the GlideList2 object for the list specified.\n\n|Name|Type|Description|\n|----|----|-----------|\n|ListID|String|The list ID for which you want the GlideList2 object.|\n\n|Type|Description|\n|----|-----------|\n|Object|The GlideList2 object or null if not found.|\n\n```\nfunction assignLabelActionViaLookupModal(tableName, listId) {\n\tvar list = GlideList2.get(listId);\n\tif (!list)\n\t\treturn;\n\n\tassignLabelViaLookup(tableName, sysIds, list.getView());\n}\n```\n\n## GlideList2 - getChecked\\(\\)\n\nReturns a comma-separated list of the sys\\_ids for the items that are checked in the associated list.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\nfunction removeLabelActionViaLookupModal(tableName, listId) {\n  var list = GlideList2.get(listId);\n  if (!list)\n    return;\n\n  var sysIds = list.getChecked();\n  if (!sysIds)\n    return;\n\n  removeLabelViaLookup(tableName, sysIds);\n}\n```\n\n## GlideList2 - getFixedQuery\\(\\)\n\nReturns the fixed query.\n\nA 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|The fixed query string for the list.|\n\n```\nvar list = GlideList2.get(container.readAttribute('list_id'));\nvar filter = this._getFilter(element);\nvar fixedQuery = list.getFixedQuery();\nif (fixedQuery)\n  filter = fixedQuery + \"^\" + filter;\n```\n\n## GlideList2 - getGroupBy\\(\\)\n\nReturns the field or comma-separated list of fields that are used to group the list.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|The field or comma-separated list of fields that are used to group the list.|\n\n```\nfunction runFilterV2Lists(name, filter) {\n  var list = GlideList2.get(name);\t\n    if (list) {\n      var groupBy = list.getGroupBy();\n      if (groupBy)  \n        filter += \"^\" + groupBy;\n\t\t\n        list.setFilterAndRefresh(filter);\n    }\n}\n```\n\n## GlideList2 - getListName\\(\\)\n\nReturns the name of the list, which is usually the table name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|The list name \\(usually the table name\\).|\n\n```\nvar list = GlideList2.get(name);\t\nvar listName = list.getListName();\n\n```\n\n## GlideList2 - getOrderBy\\(\\)\n\nReturns the first field used to order the list.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|The field by which to order the list. Empty if the list is not ordered.|\n\n```\nvar list = GlideList2.get(listId);\nif (!list)\n  return;\nvar orderBy = list.getOrderBy();\n```\n\n## GlideList2 - getParentTable\\(\\)\n\nReturns the name of the parent table for a related list \\(the table associated with the form\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|The parent table name.|\n\n```\nfor (var id in GlideLists2) {\n  var list = GlideLists2[id];\n  if (list.getTableName() == listTableName && list.getParentTable() == tableName)\n    return list.getContainer();\n}\n\n```\n\n## GlideList2 - getQuery\\(Boolean orderBy, Boolean groupBy, Boolean fixed, Boolean all\\)\n\nReturns the encoded query string for the list.\n\n<table id=\"table_us2_nww_15\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\norderBy\n\n</td><td>\n\nBoolean\n\n</td><td id=\"gList_parmDesc_orderByB\">\n\nOptional. Flag that indicates whether to include orderBy in results.Valid values:\n\n-   true: Include orderBy in results.\n-   false: Do not include orderBy in results.\n\n Default: false\n\n</td></tr><tr><td>\n\ngroupBy\n\n</td><td>\n\nBoolean\n\n</td><td id=\"gList_parmDesc_groupByB\">\n\nOptional. Flag that indicates whether to include groupBy in results.Valid values:\n\n-   true: Include groupBy in results.\n-   false: Do not include groupBy in results.\n\n Default: false\n\n</td></tr><tr><td>\n\nfixed\n\n</td><td>\n\nBoolean\n\n</td><td id=\"gList_parmDesc_fixed\">\n\nOptional. Flag that indicates whether to include fixed query in results.Valid values:\n\n-   true: Include fixed query in results.\n-   false: Do not include fixed query in results.\n\n Default: false\n\n</td></tr><tr><td>\n\nall\n\n</td><td>\n\nBoolean\n\n</td><td id=\"gList_parmDesc_all\">\n\nDefault. Flag that indicates whether to include orderBy, groupBy, and fixed query in results.Valid values:\n\n-   true: Include orderBy, groupBy, and fixed query in results.\n-   false: Do not include all three options in results.\n\n Default: true\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Encoded query string for the list.|\n\n```\nvar list = GlideList2.get(this.listID);\nvar ajax = new GlideAjax(\"AJAXJellyRunner\", \"AJAXJellyRunner.do\");\n  ajax.addParam(\"sysparm_query_encoded\", list.getQuery({groupby: true, orderby: true}));\n  ajax.addParam(\"sysparm_table\", list.getTableName());\n  ajax.addParam(\"sysparm_view\", list.getView());\n```\n\n## GlideList2 - getRelated\\(\\)\n\nReturns the related list field that associates the related list to the parent form.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|Field that connects the list to the parent form.|\n\n```\nvar list = GlideList2.get(name);\nvar related = list.getRelated();\nif (related) \n  ajax.addParam(\"sysparm_is_related_list\", \"true\");\n```\n\n## GlideList2 - getTableName\\(\\)\n\nReturns the table name for the list.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|Returns the table name for the list.|\n\n```\nGlideList2.getListsForTable = function(table) {\n    var lists = [];\n    for (var id in GlideLists2) {\n        var list = GlideLists2[id];\n        if (list.getTableName() == table)\n            lists.push(list);\n    }\n    return lists;\n}\n```\n\n## GlideList2 - getView\\(\\)\n\nReturns the view used to display the list.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|The name of the view.|\n\n```\nfunction assignLabelActionViaLookupModal(tableName, listId) {\n\tvar list = GlideList2.get(listId);\n\tif (!list)\n\t\treturn;\n\n\tassignLabelViaLookup(tableName, sysIds, list.getView());\n}\n```\n\n## GlideList2 - getTitle\\(\\)\n\nReturns the list title.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|The list title.|\n\n```\nvar list = GlideList2.get(name);\t\nvar listTitle = list.getTitle();\n\n```\n\n## GlideList2 - isUserList\\(\\)\n\nReturns **true** if the list has been personalized by the user by choosing the list mechanic and changing the list layout.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the list layout has been changed.|\n\n```\nvar list = GlideList2.get(listId);\nif (!list)\n  return;\nif (list.isUserList())\n  var tableName = list.getTableName();\n```\n\n## GlideList2 - refresh\\(Number firstRow, String additionalParms\\)\n\nRefreshes the list. The **orderBy** part of the list filter is ignored so that the list uses its natural ordering when it is refreshed.\n\n<table id=\"table_plc_vmx_15\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nfirstRow\n\n</td><td>\n\nNumber\n\n</td><td id=\"gList_parmDesc_firstRowN\">\n\nThe first row to appear in the list.Default: First row of the current view.\n\n</td></tr><tr><td>\n\nadditionalParms\n\n</td><td>\n\nString\n\n</td><td id=\"gList_parmDesc_addtl\">\n\nOptional name-value pairs that are submitted with the list refresh request.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\n```\n$timeout(function() {\n  if (GlideList.lists) {\n    var list = GlideList.get(name);\n    if (list) {\n       if (sortBy) {\n         if (sortDirection == 'ASC')\n            list.sort(sortBy);\n         else\n            list.sortDescending(sortBy);\n         }  \n       list.refresh();\n     }\n   }\n}\t\t\t\n```\n\n## GlideList2 - refreshWithOrderBy\\(Number firstRow, String description\\)\n\nRefreshes the list. The **orderBy** part of the list filter is included if it is specified for the list.\n\n<table id=\"table_rlc_vmx_15\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nfirstRow\n\n</td><td>\n\nNumber\n\n</td><td id=\"gList_parmDesc_firstRowN\">\n\nThe first row to appear in the list.Default: First row of the current view.\n\n</td></tr><tr><td>\n\ndescription\n\n</td><td>\n\nString\n\n</td><td id=\"gList_parmDesc_description\">\n\nOptional name-value pairs that are submitted with the list refresh request.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\n```\nga.getXML(function(serverResponse) {\n  var response = serverResponse.responseXML.getElementsByTagName(\"response\")[0];\n  if (response) {\n    var list = GlideList2.getByName(\"backlog_stories\");\n    list.refreshWithOrderBy();\n    var status = response.getAttribute('status');\n    $j('html, body').animate({scrollTop: $j(\"#\"+data.record.sys_id).offset().top},500);\n    if (status == 'failure') {\n      alert('${gs.getMessage(\"Story cannot be created. Team is not associated with any project.\")}');\n    }\n  }\n}\n```\n\n## GlideList2 - setFilter\\(String filter\\)\n\nSets the encoded query string for the list, ignoring the **orderBy** and **groupBy** parts of the query string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|filter|String|Encoded query string in standard Glide format. See [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nlist = GlideList2.get($(side+\"ContentDivRelease\").select(\".list_div\")[0].getAttribute(\"id\"));\nif (list) {\n  list.setFilter(\"active=true\");\n  list.refresh(1);\n }\n```\n\n## GlideList2 - setFilterAndRefresh\\(String filter\\)\n\nSets the encoded query string for the list, including the **orderBy** and **groupBy** if specified, and then refreshes the list using the new filter.\n\n|Name|Type|Description|\n|----|----|-----------|\n|filter|String|Encoded query string.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nfunction updateListFilter(projectID) {\n  var list = GlideList2.getByName(\"backlog_stories\");\n  var fixedQuery = $('hdn_additional_filters').value;\n  if(!projectID) {\n      list.setFilterAndRefresh(fixedQuery + \"^ORDERBYteam_index\");\n      list.setOrderBy(\"team_index\");\n  }\n}\n```\n\n## GlideList2 - setFirstRow\\(Number rowNum\\)\n\nSets the first row that appears in the list when the list is refreshed.\n\n|Name|Type|Description|\n|----|----|-----------|\n|rowNum|Number|Row number of the first row to display.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar nextRow = 0;\nvar rowsPerPage = 20;\nvar list = GlideList2.get(listId);\nif (!list)\n  return;\nlist.setFirstRow(nextRow);\nnextRow = nextRow + rowsPerPage;\n\n```\n\n## GlideList2 - setGroupBy\\(String groupBy\\)\n\nSets the list **groupBy** criteria for a single field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|groupBy|String|The **groupBy** criteria for the list.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nfunction runContextAction(listId) {\n  var g_list = GlideList2.get(listId);\n  g_list.setGroupBy('');\n  g_list.refresh(1);\n}\n```\n\n## GlideList2 - setOrderBy\\(String orderBy\\)\n\nSets the **orderBy** criteria for the list.\n\nFor 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|orderBy|String|Single or multiple orderBy fields.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            updateOrderBy: function(orderBy){\n  var list = GlideList2.get(this.listID);\n  if (list)\n    list.setOrderBy(orderBy);\n};\n```\n\n## GlideList2 - setRowsPerPage\\(Number rows\\)\n\nSets the number of rows per page to display.\n\n|Name|Type|Description|\n|----|----|-----------|\n|rows|Number|The number of rows to display.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nlink: function(scope) {\n  var list = GlideList2.get(scope.listId);\n  list.setRowsPerPage(scope.maxRows);\n  list.setFilterAndRefresh(scope.tableQuery);\n}\n```\n\n## GlideList2 - showHideGroups\\(Boolean showFlag\\)\n\nShows or hides all the groups within the list and saves the current collapsed/expanded state of the groups as a user preference.\n\n|Name|Type|Description|\n|----|----|-----------|\n|showFlag|Boolean|If **true**, shows the groups within the list.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nfunction showHideAllGroups(showFlag) {\n  var list = GlideList2.get(listId);\n  if (!list)\n    return;\n  list.showHideGroups(showFlag);\n}\n```\n\n## GlideList2 - showHideList\\(Boolean showFlag\\)\n\nDisplays or hides the list and saves the current collapsed/expanded state of the list as a user preference.\n\n|Name|Type|Description|\n|----|----|-----------|\n|showFlag|Boolean|If **true**, displays the list.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nGlideList2.toggleAll = function(expandFlag) {\nfor (var id in GlideLists2) {\n  var list = GlideLists2[id];\nlist.showHideList(expandFlag);\n}\n```\n\n## GlideList2 - sort\\(String field\\)\n\nSorts the list in ascending order and sets the field as an **orderBy** column.\n\n|Name|Type|Description|\n|----|----|-----------|\n|field|String|Field to use to sort the list.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n$timeout(function() {\n  if (GlideList.lists) {\n    var list = GlideList.get(name);\n    if (list) {\n       if (sortBy) {\n         if (sortDirection == 'ASC')\n            list.sort(sortBy);\n         else\n            list.sortDescending(sortBy);\n         }  \n       list.refresh();\n     }\n   }\n}\n```\n\n## GlideList2 - sortDescending\\(String field, Number amount\\)\n\nSorts a single field in the list in descending order and sets the field as an **orderByDescField** column.\n\n|Name|Type|Description|\n|----|----|-----------|\n|field|String|Field to use to sort the list.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n$timeout(function() {\n  if (GlideList.lists) {\n    var list = GlideList.get(name);\n    if (list) {\n       if (sortBy) {\n         if (sortDirection == 'ASC')\n            list.sort(sortBy);\n         else\n            list.sortDescending(sortBy);\n         }  \n       list.refresh();\n     }\n   }\n}\n```\n\n## GlideList2 - toggleList\\(\\)\n\nToggles the display of the list and saves the current collapsed/expanded state of the list as a user preference.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar list = GlideList2.get(listId);\nif (!list)\n  return;\nlist.toggleList();\n```\n\n## GlideList2 - toggleListNoPref\\(\\)\n\nToggles the display of the list but does not save the current collapsed/expanded state of the list as a user preference.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar list = GlideList2.get(listId);\nif (!list)\n  return;\nlist.toggleListNoPref();\n```\n\n"}}