Slow query from Service Portal Related List widget (from New Rocket) querying whole table instead of just relevant recordsIssue ServiceNow Parter, NewRocket Inc, published a widget named "NewRocket Related List" with the id "nr-related-lists" that creates a related list component on your Service Portal pages by pulling back all the related lists on the normal form/view and rendering those with the out-of-box "widget-data-table". It looks like this: Customers can download and install the widget from serviceportal.io. The widget doesn't work for Defined Related Lists (i.e., ones defined in the sys_relationship table). If the view displayed for a given table includes a Defined Related List, this UI will simply appear to not return any records for that list. However, in the backend, it will still query the entire target table. That is potentially a very slow query.ReleaseAll releasesCauseThe code defined pulls back all the related list for the "sp" view of the given table. If no "sp" view has been defined then it will use the Default view. The code basically assumes that only related lists built from reference fields will be on the view and if a Defined Related list is on the view then the "list.field" variable will be unexpectedly "undefined". var f = $sp.getForm(data.table, data.sys_id, data.query); data.related_lists = f._related_lists; for (var i in data.related_lists) { var list = data.related_lists[i]; var params = { table: list.table, filter: list.field+"="+data.sys_id, view: 'sp', title: list.label }; if (options.page) { var page = new GlideRecord('sp_page'); if (page.get(options.page)) data.page = page.getDisplayValue('id'); } if (!data.page) { data.page = "form"; } list.widget = $sp.getWidget('widget-data-table', params); } When the issue happens, in your Browser Developer tools network tab you'll see the {filter: "undefined={sys_id}"... in the request Payload: In the localhost logs (AKA Node Logs) you will potentially see warnings like the following: WARNING *** WARNING *** QueryEventLogger: Invalid query detected, please check logs for details [Unknown field undefined in table {table_name}] The related list will fail to return any results, which is annoying, but the resulting slow query is the real danger. The resulting query execute with no filter specified. If looking for the first 20 records in your table with no filter specified results in a very slow query, then this could be problematic - especially for customers with a large amount of users frequently looking at forms in Service Portal.ResolutionTo fix the issue you can just remove any Defined Related Lists from the "sp" view of the desired related list. You might need to make an "sp" view to do this. Also, you can put a protective code change in the NewRocket code to skip to the next related list in the case that the list.field variable is not defined. For example, consider the following, improved code excerpt: var f = $sp.getForm(data.table, data.sys_id, data.query); data.related_lists = f._related_lists; for (var i in data.related_lists) { var list = data.related_lists[i]; // protective fix for Defined Related Lists (names have "REL") that are not supported by this widget if (!list.field) continue; var params = { table: list.table, filter: list.field+"="+data.sys_id, view: 'sp', title: list.label }; if (options.page) { var page = new GlideRecord('sp_page'); if (page.get(options.page)) data.page = page.getDisplayValue('id'); } if (!data.page) { data.page = "form"; } list.widget = $sp.getWidget('widget-data-table', params); }Related LinksSince this is not ServiceNow code we cannot guarantee that this recommended solution will work, nor will we help customers implement it, nor will we support any future issues that arise as a result of this customization. The code itself stipulates that NewRocket has provided this code without warranty of any kind.