Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Exclude sys tables from dropdown and include database views

abhinavmoha
Tera Contributor

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.

abhinavmoha_0-1746509671516.png

This is the dictionary entry related to this dropdown:

abhinavmoha_1-1746509759600.png

 

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