How to stop duplicate events being fired if the user ID is the same?

matthew_hughes
Kilo Sage

I've got a flow Action where I'm trying to stop group managers of tasks in the 'x_lbg_group_recert_grp_recertification' table receiving the same email more than once.

I'm using the following inputs:

matthew_hughes_0-1746194396892.png

 

I'm trying to use the below script to put all of the group managers into an Array and to stop any duplicate user Sys IDs from being added:

(function execute(inputs, outputs) {

    var managers = [];
   
    var grRecertTasks = new GlideRecord('x_lbg_group_recert_grp_recertification');
    grRecertTasks.get(inputs.RecertTask);

    var recertManagers = grRecertTasks.group_manager.split(',');
    var grUsers = new GlideRecord('sys_user');
    grUsers.addQuery("sys_id", "IN", recertManagers);
    grUsers.query();

    while(grUsers.next()){
        var manager = grUsers.getValue('sys_id');
        if(!(managers.includes(manager))) {
            managers.push(manager);
            gs.info('Managers are ' + managers);
        }
    }

    for (var recert = 0; recert < managers.length; recert++){
        var grUserOwner = new GlideRecord('sys_user');
        if(grUserOwner.get(managers[recert])){
            gs.info("grUserOwner" + grUserOwner + "managers.email" + managers.email);
            gs.eventQueue('lbg.group.recert.group.manager', grUserOwner, managers.email);
        }
    }


/*if (typeof globalNotifiedManagers === 'undefined') {
    globalNotifiedManagers = new Set();
}

var recertTasks = fd_data.trigger.current;
var manager = recertTasks.group_manager;

//Changing below condition to check if email address is already in the set and "manager" = true and has email address
if (manager && manager.email && !globalNotifiedManagers.has(manager.email)) {
    globalNotifiedManagers.add(manager);
   
   
}*/


})(inputs, outputs);
 
I'm triggering the action via the following:
matthew_hughes_1-1746194492147.png

The flow is being triggered by a scheduled job when records within the x_lbg_group_recert_grp_recertification table are being created. However, what I'm finding in the logs is that the same user Sys ID is generating more than once, and the events are not being generated. 

 

I was just wondering if someone else has faced this issue before and what I need to do to stop potentially duplicate emails being sent to the same group manager.

 

 

0 REPLIES 0