Name
sn_em_tbac.EvtMgmtTagBasedAlertClusteringAllowedFields
Description
Must have a process method. The process method returns an array of string that are the FIELD NAMES that are allowed to be selected from the source table. Any field that is not part of the returned array will not be displayed and won t be available for selection.
Script
var EvtMgmtTagBasedAlertClusteringAllowedFields = Class.create();
EvtMgmtTagBasedAlertClusteringAllowedFields.prototype = {
type: 'EvtMgmtTagBasedAlertClusteringAllowedFields',
initialize: function() {
this.SEPARATOR = ',';
// Comma separated string of excluded fields from em_alert, e.g. 'parent, type', which is converted into an array.
this.userExcludedAlertFields = gs.getProperty('sn_em_tbac.tag_excluded_alert_fields', '').split(this.SEPARATOR);
// Comma separated string of excluded fields from cmdb_ci, e.g. 'cost_cc, delivery_date', which is converted into an array.
this.userExcludedCmdbCiFields = gs.getProperty('sn_em_tbac.tag_excluded_cmdb_ci_fields', '').split(this.SEPARATOR);
},
/**
* this process() function is called automatically when the source is selected in the tag form.
* sourceTable - String - the name of the table to filter its fields by, e.g. em_alert.
* callerTable - String - sn_em_tbac_alert_clustering_tags, unless called from a different table.
*/
process: function(sourceTable, callerTable) {
var includedFields = [];
// Return default value - empty array if sourceTable doesn't exist.
if (!sourceTable) {
return includedFields;
}
// Table-specific fields that will be excluded from the choice list.
// This variable is populated ahead, based on the given 'sourceTable' argument.
var specificFieldsToExclude;
// Shared fields (cross-tables) that will be excluded from the choice list (for all tables).
var sharedFieldToExclude = [
'sys_domain',
'sys_domain_path',
'sys_mod_count',
'sys_updated_on',
'sys_updated_by',
'sys_created_on',
'sys_created_by',
'', // Empty column name
];
// Exclusive fields per alert source
switch (sourceTable) {
case 'em_alert':
specificFieldsToExclude = [
'acknowledged',
'additional_info', // Has its own Definition source
'sn_alert_tags', // Has its own Definition source
'category',
'classification',
'correlation_group',
'correlation_rule_group',
'event_count',
'flap_count',
'flap_last_state',
'flap_last_update_time',
'flap_start_window',
'group',
'group_source',
'incident', // Task: Irrelevant and non-existent on alert creation
'initial_event_time',
'initial_remote_time',
'is_group_alert',
'kb',
'kb_url',
'last_event_time',
'last_remote_time',
'last_update_time_by_event',
'maintenance',
'number',
'parent', // Parent: Irrelevant and non-existent on alert creation
'priority_breakdown',
'priority_json',
'severity',
'state',
'remote_task_id', // Remote Task: Irrelevant and non-existent on alert creation
'sn_source_event_id',
'sn_extra_data',
'sn_num_work_notes',
'sn_services', // Impacted Services: Irrelevant and non-existent on alert creation
'sn_priority',
'sn_priority_group',
'sys_id',
'work_notes',
];
// Concat the provided user excluded em_alert fields.
specificFieldsToExclude = specificFieldsToExclude.concat(this.userExcludedAlertFields);
break;
case 'cmdb_ci':
specificFieldsToExclude = [
'assigned', // Date/Time
'attested', // True/False
'attested_date', // Date/Time
'can_print', // True/False
'checked_in', // Date/Time
'checked_out', // Date/Time
'comments', // String
'cost', //Float
'cost_cc', // String - Currency
'delivery_date', // Date/Time
'due', // Date/Time
'due_in', // String
'duplicate_of', // Reference - Configuration Item
'fault_count', // Integer
'first_discovered', // Date\Time
'install_date', // Date\Time
'install_status', // Integer
'justification', // String
'last_discovered', // Date\Time
'maintenance_schedule', // Date\Time
'managed_domain', // True/False
'operational_status', // Integer
'order_date', // Date\Time
'purchase_date', // Date\Time
'skip_sync', // True/False
'start_date', // Date\Time
'unverified', // True/False
'warranty_expiration', // Date\Time
];
// Concat the provided user excluded cmdb_ci fields.
specificFieldsToExclude = specificFieldsToExclude.concat(this.userExcludedCmdbCiFields);
break;
}
// Concat exclusions arrays and convert them into a comma-separated string.
var excludedFields = [].concat(sharedFieldToExclude, specificFieldsToExclude).join(this.SEPARATOR);
// Query the sourceTable fields, without the excluded fields.
var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name', sourceTable);
gr.addEncodedQuery('elementNOT IN' + excludedFields);
gr.query();
while (gr.next()) {
includedFields.push(gr.getValue('element'));
}
// Return only the included fields.
return includedFields;
},
};
Sys ID
6c3e38efb73030107c038229ce11a90a