- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2018 09:48 AM
I have a requirement where we created a table XYZ and a record producer , when the record producer is submitted the record will be inserted in the the table XYZ , when ever a new record is inserted, we need to send a notification to a group ,
if user is John who submitted the record producer , we need to get john's email address and send message from that, not from default ServiceNow address. and cc the user too
and If a record has an attachment, send the attachment along with the outbound message.
How do we achieve this ?
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2018 09:58 AM
It worked for me. Here is the Code I tested:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
email.setFrom(current.opened_by.name+" <"+current.opened_by.email+">");
printattachments();
function printattachments(){
var gr =new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
while(gr.next()){
template.print('Attachment: <a href="http://'+gs.getProperty("instance_name")+'.service-now.com/sys_attachment.do?sys_id='+ gr.sys_id+'">'+ gr.file_name+'</a>');}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2018 05:30 PM
Follow below steps:
Step-1: Create a new notification and select the XYZ table. Click on 'Advanced view' related link and check 'Send to event creator' field. also select the 'Users/Groups in fields' in 'who will receive tab' with specific group.
Step-2: Create an notification email script with the below code: (for example email script name is : email_script_abc)
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
printattachments();
function printattachments(){
var gr =new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
while(gr.next()){
template.print('Attachment: <a href="http://'+gs.getProperty("instance_name")+'.service-now.com/sys_attachment.do?sys_id='+ gr.sys_id+'">'+ gr.file_name+'</a>');}
}
})(current, template, email, email_action, event);
Step-3:
add this code to your notification Message HTML:
${mail_script:email_script_abc}
Hope this will help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2018 07:16 AM
Thanks for the attachment part ,Its working perfect . now how do send that notification as the user ( i mean i don't want that group receive the email from service now email , it should look like its coming from users email )
Can you please help me with that too
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2018 10:40 AM
You can use this code in email script to override the Sender email:
email.setFrom(gs.getUser().email);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2018 11:48 AM