Email getting triggered multiple times for same notification

Shreya3
Tera Contributor

Hi Team,

I need inputs to check an issue in lower instance. An email is triggering multiple times(more than 5) for the same notification. It is happening across all the notifications which is configured. there is 1 schedule job 1 email script 1 event for all 4 notifications.

The conditions are good and many mails are triggering within a sec difference.

Kindly let me know what could be the issue.

Thanks for the reply in advance.

 

4 REPLIES 4

Mark Manders
Mega Patron

Please share your code. Without that it is guessing. Probably the scheduled job is triggering the event multiple times.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Mark Manders
Mega Patron

Try this:

// Create an Array of Escalations
var escArr = [
    { type: 'first', query: 'short_description=IRM SOX Control Remediation Task^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()' },
    { type: 'second', query: 'short_description=IRM SOX Control Remediation Task^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()' },
];

// Consolidate Escalations Processing
var uniqueQueries = {};
for (var esc in escArr) {
    var escObj = escArr[esc];
    if (!uniqueQueries[escObj.query]) {
        uniqueQueries[escObj.query] = [];
    }
    uniqueQueries[escObj.query].push(escObj.type);
}

for (var query in uniqueQueries) {
    var types = uniqueQueries[query];
    var taskRec = new GlideRecord('sc_task');
    taskRec.addEncodedQuery(query);
    taskRec.query();
    while (taskRec.next()) {
        for (var i = 0; i < types.length; i++) {
            var escType = types[i];
            var evtObj = {
                escalation: escType,
                eventUsers: null
            };
            if (escType == 'first') {
                evtObj.eventUsers = taskRec.cmdb_ci.u_technology_ci_owner.manager.getValue();
            }
            if (escType == 'second') {
                evtObj.eventUsers = taskRec.cmdb_ci.u_technology_ci_owner.manager.manager.getValue();
            }
            // Process the Event
            gs.eventQueue('syf.sox.escalation', taskRec, evtObj.eventUsers, JSON.stringify(evtObj));
        }
    }
}

function _createIncident(taskRec) {
    // Create a value to return
    var incNum = '';
    var incVals = _getIncidentValues(taskRec);
    var incRec = new GlideRecord('incident');
    // Check for existing Incidents
    incRec.addActiveQuery();
    incRec.addQuery('u_service_request', incVals.u_service_request);
    incRec.query();
    if (incRec.next()) {
        return null;
    } else {
        // Create a new Incident
        incRec.initialize();
        // Set values based on the Task
        for (var val in incVals) {
            var incCol = val;
            var incVal = incVals[val];
            incRec.setValue(incCol, incVal);
        }
        if (incRec.insert()) {
            incNum = incRec.getValue('number');
        }
        return incNum;
    }
}

function _getIncidentValues(taskRec) {
    // Create a Map of value object properties
    var valMap = {
        'assigned_to': taskRec.cmdb_ci.u_technology_ci_owner.getValue(),
        'assignment_group': taskRec.getValue('assignment_group'),
        'caller_id': taskRec.request.requested_for.getValue(),
        'cmdb_ci': taskRec.getValue('cmdb_ci'),
        'opened_by': taskRec.request.requested_for.getValue(),
        'u_service_request': taskRec.getValue('request_item'),
        'category': "Authentication\\Authorization",
        'description': "Terminated users with access to CI since past 4 weeks" + '\n' + taskRec.getValue('description'),
        'priority': "2",
        'short_description': "Non-SIAM ACL/SOX Control Remediation",
        'subcategory': "change privileges/right",
        'urgency': "2"
    };
    // Return the Map
    return valMap;
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

  if (evtObj.escalation == 'third') {
                evtObj.eventUsers = taskRec.cmdb_ci.u_technology_ci_owner.manager.manager.manager.getValue();
            }
            // The fourth Escalation generates an Incident
            if (evtObj.escalation == 'fourth') {
                evtObj.eventUsers = taskRec.cmdb_ci.u_technology_ci_owner.getValue();
                var incNum = _createIncident(taskRec);
                if (!gs.nil(incNum)) {
                    taskObj.action = 'incident';
                    taskObj.incidentNumber = incNum;
                } else {
                    taskObj.action = 'error';
                }
            }
            // Add the Object to the Task List
            returnObj.taskList.push(taskObj);
Can I add these all previous  line of code  later in your code if have to check for all the notification with the given query for(first/second/third/fourth)? As right now you have removed third and fourth query in the above and  also all these lines of code.

it is not working