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
‎08-30-2017 11:29 AM
Can you please click on the related link "Advanced view" and check again. In case you still don't see this then personalize the form layout and make sure the field is present on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2017 01:35 PM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: Scripting for Email Notifications
Visit http://docs.servicenow.com for the latest product documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2016 07:28 AM
Never tried without To field. You just give a try.
Let me know the result as I am also interested to know the result !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2016 07:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2018 12:12 PM
I have a similar requirement and used a mail script to modify the email_action.recipient_users directly.
(function runMailScript(current, template, email, email_action, event) {
var user = new GlideRecord('sys_user');
user.addEncodedQuery('user_name=' + current.sys_created_by);
user.query();
while (user.next()){
email.addAddress("to", user.email,user.name);
template.print(user.name);
email_action.recipient_users += user.sys_id+",";
}
})(current, template, email, email_action, event);