Exclude sys tables from dropdown and include database views
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 10:40 PM
We are trying to build a scoped app with one form having dropdown which lists the tables (from sys_db_object) and views(from sys_db_view). We are trying to exclude sys tables and sys views and we are able to achieve this with adding attributes in dictionary entry as shown in screenshot.
This is the dictionary entry related to this dropdown:
The script "GetAllTablesAndViews" excludes sys tables and views
function tableChoicesScript() {
var result = '';
var tables = [];
// Get non-sys tables
var tableGr = new GlideRecord('sys_db_object');
tableGr.addQuery('name', 'NOT LIKE', 'sys_%');
tableGr.addNotNullQuery('name');
tableGr.query();
while (tableGr.next()) {
tables.push(tableGr.getValue('name'));
}
// Get views where base table is not a sys_ table
var viewGr = new GlideRecord('sys_db_view');
viewGr.query();
while (viewGr.next()) {
var baseTableSysId = viewGr.getValue('base_table');
if (baseTableSysId) {
var baseTableGr = new GlideRecord('sys_db_object');
if (baseTableGr.get(baseTableSysId)) {
var baseTableName = baseTableGr.getValue('name');
if (!baseTableName.startsWith('sys_')) {
tables.push(viewGr.getValue('name'));
}
}
}
}
// Sort tables alphabetically
tables.sort();
// Format the result as a choice list string
for (var i = 0; i < tables.length; i++) {
This script works when run it in script-background, but as an attribute here in above screenshot it wont work for views. Whats the right approach?
0 REPLIES 0