- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2016 02:48 PM
Can I get the list of recipients in a email notification script which I am using the email, before it is sent out. I know we can get if it is a field in the form, but from the
whom to fields?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2016 10:46 AM
Ravali,
Here is your complete email script. I have tested this and it should work for you as well.
var userArr=[];
var count=0;
var fieldsArr1=email_action.recipient_users.toString().split(',');
var fieldsArr2=email_action.recipient_groups.toString().split(',');
var fieldsArr3 = email_action.recipient_fields.toString().split(',');
if(fieldsArr1)
{
for(var i=0; i<fieldsArr1.length; i++){
userArr.push(fieldsArr1[i]);
}
}
if(fieldsArr2)
{
for(var i=0; i<fieldsArr2.length; i++){
var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group',fieldsArr2[i]);
gr.query();
while(gr.next()){
userArr.push(gr.getValue('user'));
}
}
}
if(fieldsArr3)
{
for(var i=0; i<fieldsArr3.length; i++){
var inc_field = fieldsArr3[i].toString();
userArr.push(current.getValue(inc_field));
}
}
if(email_action.event_parm_1!='')
{
userArr.push(event.parm1);
}
if(email_action.event_parm_2!='')
{
userArr.push(event.parm2);
}
var arrayUtil = new ArrayUtil();
var gr1= new GlideRecord("sys_user_has_role");
gr1.addQuery('user','IN',arrayUtil.unique(userArr).toString());
gr1.addQuery('role.name','itil');
gr1.query();
if(gr1.getRowCount()==arrayUtil.unique(userArr).length){
template.print("Click here to View: "+'${URI_REF}');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2016 03:40 PM
Try this in the email script
<mail_script>
var userArr= current.watch_list.toString().split(',');
userArr.push(current.getValue("assigned_to"));
var gr= new GlideRecord("sys_user_has_role");
gr.addQuery('user','IN',userArr.toString());
gr.addQuery('role.name','itil');
gr.query();
if(gr.getRowCount()==userArr.length){
template.print(//here you will put in the link);
}
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2016 03:57 PM
are you trying to put the assigned to and watch list in an array and loop through it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2016 04:18 PM
Yes, I am seeing if all the users in assigned to and watchlist have itil
role
On Monday, July 11, 2016, ryadavalli <community-no-reply@servicenow.com>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2016 09:34 AM
HI abhinay,
But this template for the email notification I am trying to modify is used in many notifications. Can I just get the people in the users, groups fields of the email notification under the who will receive tab in the email notification itself like all the recipients?
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2016 09:38 AM
Use "email_action.recipient_fields" in the email script. This will give you all the users in user/group fields