Sending email notification after group has been deleted

Aakriti_Poudel
Tera Contributor

Error: getEventTarget() called with invalid record reference: sys_user_group.d477df9c976f791035ddbfb6f053affd for event: delete.notification.registry, could have been deleted.

PS: I have created a business rule - applied when to run as 'before' , 'delete'
The business rule is as follows:

(function executeRule(current, previous /*null when async*/) {

    try {

        // Set up incident record

        var incidentGR = new GlideRecord('incident');

        incidentGR.initialize();

        incidentGR.setValue('short_description', 'Group Deleted: ' + current.name);

        incidentGR.setValue('assignment_group', '12a586cd0bb23200ecfd818393673a30'); // incident management group

        incidentGR.setValue('caller_id', '6816f79cc0a8016401c5a33be04be441'); // system administrator

        var sysID = incidentGR.insert();// fetch sysid of created incident

 

// Fetch incident number

var gr = new GlideRecord('incident');

if(gr.get(sysID)){

        // Send email notification

var groupName = current.name;

var incidentNum = gr.number; 

 

gs.eventQueue('delete.notification.registry', incidentGR,groupName, incidentNum);

}

    } catch (ex) {

        gs.error('Error in business rule: ' + ex);

    }

})(current, previous);


Could someone help me with it?

1 REPLY 1

umaaggarwal
Giga Guru
Giga Guru

Do not provide the group name because group will not be existing after it is deleted, however I would suggest get the group members list in an array and pass that array in the event parameter so that it has no dependency for group while it sends the notifications

 

Hope that helps