Name

global.EvtMgmtAlertTagsValidation

Description

  1. canUseEmAlertTagsTable - Returns true if alert tags feature is enabled by property AND em_alert_tags table exists. 2. Go over the 3 table a. em_match_field --> mapping field b. em_mapping_rule --> to_field field c. em_compose_field --> field field 3. addNewAlertTag - insert to em_alert_tags table only if doesn t exist

Script

var EvtMgmtAlertTagsValidation = Class.create();
EvtMgmtAlertTagsValidation.prototype = {
  initialize: function() {
      this.evtMgmtAlertTagsUtil = new global.EvtMgmtAlertTagsUtil();
  },

  validateTagsExistance: function() {
      if (!this.evtMgmtAlertTagsUtil.canUseEmAlertTagsTable()) {
          return;
      }
  	// we want to concatinate the tags from 3 tables and make them unique
      var tagList = this.getValidTagListFromTableField("em_compose_field", "field");
      tagList = this.uniqueArray(tagList.concat(this.getValidTagListFromTableField("em_mapping_rule", "to_field")));
      tagList = this.uniqueArray(tagList.concat(this.getValidTagListFromTableField("em_match_field", "mapping")));
      this.addTagsToTable(tagList);

  },

  getValidTagListFromTableField: function(table, field) {
      var listOfTags = [];
      var gr = new GlideRecord(table);
      gr.query();
      while (gr.next()) {
          var value = gr.getValue(field);
          if (!gs.nil(value)) {
              var mappingFields = value.split(',');
              for (var i = 0; i < mappingFields.length; i++) {
                  if (!gs.nil(mappingFields[i].trim())) {
                      if (this.evtMgmtAlertTagsUtil.isValidAlertTagName(mappingFields[i])) 
  						listOfTags.push(mappingFields[i]);
                  }
              }
          }
      }
      return listOfTags;
  },

  addTagsToTable: function(tags) {
   if (!tags || !Array.isArray(tags))
       return;
   if (this.evtMgmtAlertTagsUtil.canUseEmAlertTagsTable()) {
       for (var i = 0; i < tags.length; i++) {
           this.evtMgmtAlertTagsUtil.addNewAlertTag(tags[i]);
       }
   }
  },

  uniqueArray: function(arrArg) {
      return arrArg.filter(function(elem, pos, arr) {
          return arr.indexOf(elem) == pos;
      });
  },
  type: 'EvtMgmtAlertTagsValidation'
};

Sys ID

5b3397e847c1e15035fb0562936d4385

Offical Documentation

Official Docs: