Name

sn_table_builder.FlowDataAPI

Description

No description available

Script

var FlowDataAPI = Class.create();

FlowDataAPI.DEFAULT_SORT_COLUMN = 'sys_updated_on';
FlowDataAPI.DEFAULT_ORDER_BY_IS_DESCENDING = true;
FlowDataAPI.prototype = {
  /**
   * options - { tableName }
   */
  initialize: function(options) {
      this.tableName = options.tableName || '';
      this.query = options && options.query || '';
      this.orderByColumn = options && options.orderByColumn;
      this.orderByIsDescending = options && options.orderByIsDescending;
  },

  build: function() {
      var result = this._validate();

      if (!result.isValid)
          return TBUtil.error(result);

      var orderByColumn = this._getSortColumn();
      var orderByIsDescending = this._isSortOrderDescending();
      var sortQuery = this._getSortQuery(orderByColumn, orderByIsDescending);

      var flows = new FlowRecords({
          tableName: this.tableName,
          query: this.query,
          sortQuery: sortQuery,
      }).getRecordDetails();
      return {
          tableName: this.tableName,
          flows: flows.rows,
          canCreate: flows.canCreate,
      };
  },

  _getSortColumn: function() {
      return this.orderByColumn || FlowDataAPI.DEFAULT_SORT_COLUMN;
  },

  _isSortOrderDescending: function() {
      return (typeof this.orderByIsDescending !== 'undefined') ? JSON.parse(this.orderByIsDescending) : FlowDataAPI.DEFAULT_ORDER_BY_IS_DESCENDING;
  },

  _getSortQuery: function(orderByColumn, orderByIsDescending) {
      return (orderByIsDescending ? 'ORDERBYDESC' : 'ORDERBY') + orderByColumn;
  },

  _validate: function() {
      var res = Validators.isValidTableRecord(this.tableName);
      if (!res.isValid) {
          res.message = gs.getMessage('Invalid Table Name passed in API request');
          return res;
      }

      return {
          isValid: true
      };
  },

  type: 'FlowDataAPI'
};

Sys ID

ff42b04d77ea811031e3b3c64b5a999c

Offical Documentation

Official Docs: