Emails are not getting triggered from event queue

Prudhvi Raj4
Tera Guru

Hi Team,

 

I have requirement to send emails to all the managers for the records in pending approval. I have written a script to get all the managers email ID and using gs.eventQueue sending emails, here few emails are getting triggered and few are not when I check in the event logs I can see for the emails sent parm1 is set to user email id and emails which are not sent parm1 is set to user name, not sure why some are picking emailID and some are user name. please suggest how to fix the issue.

 

Script to trigger emails

 

setDriverPendingEmails: function(){
        var driver = new GlideRecord('table name');
        driver.addEncodedQuery('status=Pending Approval');
        driver.query();
        var email_to =[];
        var arrayUtil = [];
        while(driver.next()){
            email_to.push(driver.adobe_ldap_id.manager.email.toString());
                for (var i = 0; i < email_to.length; i++) {
                    if(arrayUtil.indexOf(email_to[i]) === -1){
                        arrayUtil.push(email_to[i]);
                        gs.eventQueue('x_adosy_adb_treasu.sendPendingApprovalsEmail',driver,arrayUtil[i].toString(),null);
                    }
                }
        }
       
    },
 
PrudhviRaj4_1-1715856834629.png

In the above screen shot couple of records are getting email ID and remaining are getting user name where emails are not going out.


 

1 ACCEPTED SOLUTION

Even if you doing like this ... you should first prepare final arrayList with unique emails and then iterate the arrayList for event trigger.

Try this one.

setDriverPendingEmails: function(){
        var driver = new GlideRecord('table name');
        driver.addEncodedQuery('status=Pending Approval');
        driver.query();
        var email_to =[];
       var arrayUtil = new global.ArrayUtil();
        while(driver.next()){
           // push all emails to array
            email_to.push(driver.adobe_ldap_id.manager.email.toString());
         } // while loop end here
         var uniqueEmails = arrayUtil.unique(email_to);
         for ( var i=0; i < uniqueEmails.length; i++){
                    gs.eventQueue('x_adosy_adb_treasu.sendPendingApprovalsEmail',driver,uniqueEmails[i].toString(),null);
         } // for loop end here     
},

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

6 REPLIES 6

Even if you doing like this ... you should first prepare final arrayList with unique emails and then iterate the arrayList for event trigger.

Try this one.

setDriverPendingEmails: function(){
        var driver = new GlideRecord('table name');
        driver.addEncodedQuery('status=Pending Approval');
        driver.query();
        var email_to =[];
       var arrayUtil = new global.ArrayUtil();
        while(driver.next()){
           // push all emails to array
            email_to.push(driver.adobe_ldap_id.manager.email.toString());
         } // while loop end here
         var uniqueEmails = arrayUtil.unique(email_to);
         for ( var i=0; i < uniqueEmails.length; i++){
                    gs.eventQueue('x_adosy_adb_treasu.sendPendingApprovalsEmail',driver,uniqueEmails[i].toString(),null);
         } // for loop end here     
},

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

DeepakC15
Tera Contributor

setDriverPendingEmails: function(){ var driver = new GlideRecord('table name'); driver.addEncodedQuery('status=Pending Approval'); driver.query(); //var email_to =[]; //var arrayUtil = []; while(driver.next()){ var email_to = driver.adobe_ldap_id.manager.email.toString(); gs.eventQueue('x_adosy_adb_treasu.sendPendingApprovalsEmail',driver,email_to.toString(),null); } },