Name

sn_decision_table.DecisionTableUtil

Description

No description available

Script

var DecisionTableUtil = (function() {

  var SYS_DB_OBJECT = 'sys_db_object';
  var SYS_DICTIONARY = 'sys_dictionary';

  return {

      /**
       * Returns comma separated list of all tables in hierarchy
       * @param tableName
       * @returns {String}
       */
      getAllTablesInHierarchy: function(tableName) {
          return new GlideTableHierarchy(tableName).getTables();
      },

      /**
       * Returns table glide record for a given name
       * @param tableName
       * @returns {GlideRecord}
       */
      getTableRecordByName: function(tableName) {
          var gr = new GlideRecord(SYS_DB_OBJECT);
          gr.addQuery("name", tableName);
          gr.query();

          while (gr.next()) {
              return gr;
          }
      },

      /**
       * Returns glide record for a table field
       * @param tableName
       * @param columnName
       * @returns {GlideRecord}
       */
      getFieldRecordByName: function(tableName, columnName) {
          var gr = new GlideRecord(SYS_DICTIONARY);
          gr.addQuery('name', 'IN', this.getAllTablesInHierarchy(tableName));
          gr.addQuery("element", columnName);
          gr.query();

          while (gr.next()) {
              return gr;
          }
      },

      /**
       * Returns list of all choice type fields for a given table
       * @param tableName
       * @param searchTerm
       * @returns {GlideRecord}
       */
      getChoiceTypeFieldsForTable: function(tableName, searchTerm) {

          // Using GlideRecord instead of GlideRecordSecure to allow fetching choiceFields for users with decision table admin role
          var choiceFieldGR = new GlideRecord(SYS_DICTIONARY);
          choiceFieldGR.addQuery('name', 'IN', this.getAllTablesInHierarchy(tableName));

          var choiceCondition = choiceFieldGR.addQuery('internal_type', 'choice');
          choiceCondition.addOrCondition('choice', 'IN', '3,1');

          if (searchTerm) {
              choiceFieldGR.addQuery('column_label', 'STARTSWITH', searchTerm);
          }

          choiceFieldGR.setLimit(50);
          choiceFieldGR.query();

          return choiceFieldGR;
      },
  };
})();

Sys ID

4741c793435d21108561af1eb9b8f283

Offical Documentation

Official Docs: