Help with notification

RudhraKAM
Tera Guru

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   

1 ACCEPTED SOLUTION

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);

 

find_real_file.png

 

View solution in original post

20 REPLIES 20

Sorry my bad we can't use gs inside email script. Use the below code, it should work:

email.setFrom(current.opened_by.name+" <"+current.opened_by.email+">");

where do i write this?

Write in same highlighted place (Line number 14 above) where you wrote before. Just override that line with this new line of code.

Also delete line 1-7 as those are written twice.

that is showing undefinedfind_real_file.png

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);

 

find_real_file.png