Name
sn_sow_em.SimilarAlertsForRF
Description
Implements extension point sn_rf.ScriptingRuleInterface Use this interface to implement a script include for rule using Scripting evaluation type
Script
var SimilarAlertsForRF = Class.create();
SimilarAlertsForRF.prototype = Object.extendsObject(sn_rf.RFScriptingRuleSNC, {
initialize: function() {
this.emAiInsightForRF = new sn_sow_em.EmAiInsightForRF();
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': this.emRfCommons.CONFIDNECE_SCORE // 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 evaluationOutputs = [];
var alertGr = new GlideRecord("em_alert");
evaluationOutputs = this.emAiInsightForRF.getRelatedAlerts(alertGr, currAlertGr);
// log number of results
this.emRfCommons.logNumberOfResults(this.type, currAlertGr.number, evaluationOutputs.length);
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: 'SimilarAlertsForRF'
});
Sys ID
59f5b4c007410110b34ce06b0fd30070