Name

sn_query_rules.QueryRulesDescriber

Description

Helper class to automatically generate descriptions for query rules.

Script

var QueryRulesDescriber = Class.create();

QueryRulesDescriber.prototype = {
  initialize: function() {},

  ensureDescription: function(gr) {
      if (gr.isValidRecord() && !this.shouldUpdate(gr))
          return;
      // generate our text...
      var text = '';
      text += "Query rule for ";
      text += gr.table;
      text += '. Users with one of the following roles (';
      text += gr.roles;
      text += ') have read access to ';
      text += gr.table;
      text += ' records that match the selected filter conditions.';
      gr.description = text;
  },

  shouldUpdate: function(gr) {
      // if we don't have a valid GlideRecord for a query rule, bail...
      if (!gr || !gr.isValidRecord() || gr.getTableName() != 'sn_query_rule')
          return false;

      // if we already have a description that we didn't write, and we're not overwriting, bail...
      var descr = '' + gr.description;
      if (descr == null)
          return true;

      var _match = descr.match(/^Query rule for .*?(?:always|(. Users with one of the following roles)) (.*?) (?:always|(have read access to)) (.*?) (?:always|(records that match the selected filter conditions.))/);

      if (_match || gs.nil(gr.description) || gr.description == '')
          return true;
      else if (!_match && !gs.nil(gr.description))
          return false;

      return true;
  },

  type: 'QueryRulesDescriber'
};

Sys ID

e74cccd60f9b10103ff81b41ff767e69

Offical Documentation

Official Docs: