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

Community Alums
Not applicable

Hi @Prudhvi Raj4 ,

Please check in user record if Darby Hughes and Araceli Berudez have email id sys_user table. I think that users don't have email in their record.

 

Please mark my answer correct and helpful if this works for you.

Thanks and Regards 

Sarthak

Hi @Community Alums 

Yes, I have checked on sys_user table emails ID's are present 

AshishKM
Kilo Patron
Kilo Patron

Hi @Prudhvi Raj4 , 

Please re-check the code logic, there is while over result set and again for loop which.

Also check the user record as suggested by @Community Alums .

 

Why you need two arrayList object, where you are pusing one arrayList object to other one.

You just need email from gliderecord query and trigger the eventQueue for each iteration. 

 

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);
         }
      
    },

 

-Thanks,

AshishKM


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

Hi @AshishKM 

 

I have two different arrays because in the first array I have duplicate email ID so I am removing the duplicate and storing them in second array and using it