How to set "Who will receive" through mail script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2014 11:13 PM
Hi Everyone,
I want to add "Who will receive' from <mail_script></mail_script>. is there any way by which we can set user/group filed in "Who will receive".
I m writing this code as below in <mail_script> in email template. But this is not working:
<mail_script>
var gr = new GlideRecord("change_request");
gr.addQuery("number", current.number);
gr.query();
if(gr.next())
{
var emailto=gr.requested_by.user_name+"@example.com";
email.setTo(emailto);
}
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2014 11:19 PM
Hi Mukesh,
You can add Email Address in your mail script by below method
email.addAddress("cc", "User's Email","Name");
email.addAddress("bcc", "Group's Email","Group Name");
But for 'To' you can make use of parm1 and parm2 functionality of Email Notifications

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2014 12:13 AM
Hi Mukesh,
Please check the below thread which will be helpful
https://community.servicenow.com/message/695278#695278
Thanks
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2014 12:43 AM
Hi Mukesh,
If you are triggering the email notification with an event, you can pass the recipients id as a parameter in the event call itself ie
gs.eventQueue("myevent.called", current, gs.getUserID(), gs.getUserName());
here parm1 is gs.getUserID() and parm2 is gs.getUserName(). In the email notification, you can select the advanced view, change 'Send when' to 'Event is fired' and you can see that in the 'Who will recieve' you have these options 'parm1 has recipient', 'parm2 has recipient', you can check that to send the email to them.
cc and bcc can be controlled via script, you can refer this wiki link for more details:-https://wiki.servicenow.com/index.php?title=Scripting_for_Email_Notifications#Adding_CC_and_BCC_Reci...
In a nutshell, you can use the below script add people in cc and bcc:-
<mail_script>
//email.addAddress(type, address, displayname);
email.addAddress("cc", "john.copy@example.com","John Roberts");
email.addAddress("bcc", "john.secret@example.com","John Roberts");
</mail_script>
Hope this helps.
Thanks & Regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2016 07:07 AM
HI Harish,
I am trying to send the email notification to bcc and cc but not to have an to address.
The lines you mentioned above <mail_script> email.addAddress......, should be put in the email notification body ?
Thanks,