Push managers of users in list collector to email notification

Cirrus
Kilo Sage

Thanks for all the community help in getting me to this point, but I have one final issue to overcome.

In our catalog item, users are added to a list collector variable. For each selected user, we want to identify their manager and email them individually (so if 10 users are selected, 10 manager emails will be sent). Using Create Event in the workflow and an email script we can identify the sys_id of each manager, but when we try and pass this into a notification the email error string says "Email contains no recipients, send ignored"

Email script:

 

(function() {
var answer = []; 
var list = current.variables.selected_user.toString();   
var listArr = list.split(',');   
for (var i=0;i<listArr.length;++i) {   
 
var user = new GlideRecord('sys_user');   
user.addQuery('sys_id',listArr[i]); 
user.query(); 
 
if(user.next()){ 
  var mgrID = user.manager;
gs.log('Selected' + mgrID);//confirms we are returning correct manager sys_id
answer.push(mgrID.toString());
gs.eventQueue('email.send',current,mgrID[i]); 
}   
}  
return "";
}());
 
Mail script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
 
          
var gr = new GlideRecord('sys_user');
gr.get(event.parm1);
template.print(gr.name);
 
})(current, template, email, email_action, event);
 
I am thinking that maybe we cannot pass the manager in this way as it is not a defined 'current' variable. In that case do we have to look at a hidden list variable to dynamically populate as users are selected and then use the same create event/email script approach that we use to notify the users (which does work as required)??
Any advice greatly appreciated.
2 REPLIES 2

Abhijit
Tera Expert

I think you are not setting to whom to sent , you are getting value for email id use below code in mail script

 

 

 

 

email.addAddress("to","email_address_of_the_user","Name_of_ther_user");