Name
sn_sow_em.RepeatedAlertsForRF
Description
Implements extension point sn_rf.ScriptingRuleInterface Use this interface to implement a script include for rule using Scripting evaluation type
Script
var RepeatedAlertsForRF = Class.create();
RepeatedAlertsForRF.prototype = Object.extendsObject(sn_rf.RFScriptingRuleSNC, {
initialize: function() {
this.emRfCommons = new sn_sow_em.EmRfCommons();
},
/**********
* Generates output schema for 'Scripting' evaluation type and returns the expected output structure of getEvaluationOutputs()
*
* @return JSON containing list of output's metadata
**********/
getEvaluationOutputSchema: function() {
return {
'status': 'success',
'schema': [
// List of records to show in pill picker
{
'name': this.emRfCommons.ALERT_RECORD_NAME, // string
'label': this.emRfCommons.ALERT_RECORD_LABEL, // string
'type': 'reference', // this value should be either 'string' or 'reference'
'referenceTable': 'em_alert'
}
],
'metaData': {
'uniqueKey': [this.emRfCommons.ALERT_RECORD_NAME], // name of the fields to uniquely identify a recommendation
'confidence': '' // name of the field which will have confidence score for the recommendation
}
};
},
/**********
* Generates evaluation outputs for given record and inputs
*
* @param param.contextRecord Current record for which we are evaluating
* @return JSON containing list of evaluation outputs
**********/
getEvaluationOutputs: function(param) {
var currAlertGr = param.contextRecord;
this.emRfCommons.logStartTime(this.type, currAlertGr.number);
var startTimeGdt = new GlideDateTime();
try {
var alertGr = new GlideRecord("em_alert");
var emAiInsight = new global.EmAiInsight();
emAiInsight.getSameAlertQuery(alertGr, currAlertGr); // add query conditions for finding repeated alerts to alertGr
alertGr.orderByDesc('initial_remote_time');
alertGr.setLimit(this.emRfCommons.TOP_N_RESULTS); //default is 10 results
alertGr.query();
// log number of results
this.emRfCommons.logNumberOfResults(this.type, currAlertGr.number, alertGr.getRowCount());
var evaluationOutputs = this.emRfCommons.insertAlertsToResultArray(alertGr, "sys_id");
this.emRfCommons.logEndTime(this.type, currAlertGr.number, startTimeGdt);
return {
'status': 'success',
'evaluationOutputs': evaluationOutputs
};
} catch (e) {
var errorMessage = this.emRfCommons.logErrorMessage(this.type, currAlertGr.number, currAlertGr.getUniqueValue(), e);
return {
'status': 'error',
'errorCode': 40001,
'errorMessage': errorMessage
};
}
},
type: 'RepeatedAlertsForRF'
});
Sys ID
b17ab4c807410110b34ce06b0fd300a9