- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 01:20 PM
In the workflow, I have a "run script" activity. In this, I got an array of emails, managers, and groups. (ie, groups[0] is name of groupA, managers[0] is the name of the manger for groupA, and emails[0] is the email address for the group manager of A). Note that the all 3 arrays have the same length. I also have a user variable, which remains unchanged throughout the workflow.
Now, i want to send am email to each element in the arrays. Something like
for (var i = 0; i < emails.length; i++){
//send email to $emails[i] that says "Hello $managers[i], the user $User_Variable has been added to your group $groups[i]."
}
I don't know how I can achieve this.
I googled this problem and I think event queue is something I can use? But I have no idea how to use event queue.
Any insight is appreciated, thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 04:03 PM
hi Youchan,
u can try this
for (var i = 0; i < emails.length; i++){
//send email to $emails[i] that says "Hello $managers[i], the user $User_Variable has been added to your group $groups[i]."
var mail = new GlideEmailOutbound();
mail.addRecipient($emails[i]);
mail.setSubject('Add user Notification');
mail.setBody('Hello $managers[i], the user $User_Variable has been added to your group $groups[i].');
mail.save();
}
You might want to manipulate the variable in the email body like 'Hello ' + managers[i] etc...
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 04:03 PM
hi Youchan,
u can try this
for (var i = 0; i < emails.length; i++){
//send email to $emails[i] that says "Hello $managers[i], the user $User_Variable has been added to your group $groups[i]."
var mail = new GlideEmailOutbound();
mail.addRecipient($emails[i]);
mail.setSubject('Add user Notification');
mail.setBody('Hello $managers[i], the user $User_Variable has been added to your group $groups[i].');
mail.save();
}
You might want to manipulate the variable in the email body like 'Hello ' + managers[i] etc...
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 08:42 PM
thank you this is definitely on the right track / what i was looking for!
I found this right before coming across your response, but i think they are similar - and what i wanted.
var emailNotification = new GlideRecord('sys_email');
emailNotification.type = 'send-ready';
emailNotification.subject = 'Email subject';
emailNotification.body = 'Email body';
emailNotification.recipients = email-adress1 + ',' + email-address2;
emailNotification.insert();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 07:09 AM
I would use a combination of the following articles to build an email notification that is triggered by an event.
Events and Email Notification - ServiceNow Wiki
http://wiki.servicenow.com/index.php?title=Email_Notifications#gsc.tab=0