Event gets triggered multiple times when selecting multiple records

Lokesh Pandey1
Tera Contributor

I have a button on the related list of one of my custom tables in workspace that I created using Action Assignment. In this related list, multiple records can be added. The records can be selected using the checkbox. I'm trying to trigger one single notification when any number of records are selected in this related list and the button is clicked. However, I'm unable to do so as multiple events are getting triggered when I select multiple records resulting in multiple emails getting triggered. This issue does not occur in native view as I've used GlideRecord in my UI action to fetch all the records and used the gs.eventQueue method outside the while loop.So, no matter how many records I select, event gets triggered only once in native. But since GlideRecord does not work on Action assignment, I wrote a Business rule to achieve the same but it's not working as I intend. 

UI Action code(Button in native that's working):-  

sendForApproval();
 
function sendForApproval() {
 
var encQuery = 'u_state=2^u_pool='+parent.sys_id;
var grAthletePool = new GlideRecord("sn_customerservice_pool_mapping");
grAthletePool.addEncodedQuery(encQuery);
grAthletePool.query();
while (grAthletePool.next()) {
 
grAthletePool.u_state = '3';
grAthletePool.update();
}
if ((grAthletePool.u_action == '1')){
gs.eventQueue("sn_customerservice.GM.Athlete.Approval_R",grAthletePool,"","");
}
action.setRedirectURL(parent);
}

Business rule code(To fire event from workspace):- 

(function executeRule(current, previous /*null when async*/) {
 
var encQuery = 'u_pool='+current.u_pool+'^u_state=3^sys_updated_onONLast 15 minutes@javascript:gs.beginningOfLast15Minutes()@javascript:gs.endOfLast15Minutes()';
var grPoolMapping = new sn_customerservice.dfsnzCommonUtil().getTableRecords('sn_customerservice_pool_mapping',encQuery);
while(grPoolMapping.next())
{
       //
}
 
gs.eventQueue("sn_customerservice.GM.Athlete.Approval_R",grPoolMapping,"","");
 
})(current, previous);

Action Assignment Code:-

if(current.u_state == '2'){
current.u_state = '3';
current.u_unique_id = newAthleteId;
current.update();
}

 

1 REPLY 1

HN1
Tera Contributor

Hi Lokesh,

Populate one of the event parms with the parent sys_id and add to the script another GlideRecord that runs on the sysevent table and search for the same event name and the same parent sys_id and only if not found create the event.

 

Mark as correct if you find this answer helpful.

Thanks.