
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2020 10:18 AM
Hello,
My use case: Every time an attachment is added to a case by anyone accept for my integration user then send an email to a particular email address with the recent attachment.
I have found this article on the community on how to create the Script Include (getAttachments) and the Business Rule on the sys_email table. https://community.servicenow.com/community?id=community_question&sys_id=acfa07addb5cdbc01dcaf3231f96...
I am not sure how this works. How do I create a notification that gets that last attachment? I need it to go to a specific email address.
Do I need to create a mail script? I am a little bit confused. Any clarification or help would be appreciated.
Thanks,
Stacy
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2020 09:37 AM
This is to send ONLY the attachment that was just attached to the record. In my case I want to send an email to our client when an attachment is attached and only that 1 attachment as they send us attachments and we only want to send those that we attach to the case not everything every time a new attachment is put on.
I have created a before insert Business Rule on the Sys Attachment table.
My condition is the table = sn_customerservice_case and the created by is NOT our integration user. (the one that sends us attachments from the customer).
I had to script the creation of the Notification and the Email Attachment.
(function executeRule(current, previous /*null when async*/ ) {
var fileName = current.file_name;
var tableName = current.table_name;
var tableSysId = current.table_sys_id;
if (tableName == 'sn_customerservice_case') {
var GR = new GlideRecord(tableName + '');
GR.addQuery('account', '8ef1ba261be30890ef6b866fdc4bcbf3');//Only send if this is our particular customer, we don't want this for all accounts.
GR.addNotNullQuery('u_client_case_id');//Only send if this field is true as this means it's an integrated case
GR.addQuery('sys_id', tableSysId + '');
GR.query();
if (GR.next()) {
var caseid = GR.u_client_case_id;
var gre = new GlideRecord('sys_email');
gre.initialize();
gre.mailbox = 'outbox';
gre.state = 'ready';
gre.target = current.sys_id;
gre.subject = "Case ID-" + caseid;
gre.recipients = 'bxxx.admin@xxx.com';
gre.body = "<p>Attached from XXX</p><p></p>";
gre.content_type = "text/html";
gre.headers = "X-ServiceNow-Source:Notification-6fbc13c0dbc41450fd899236db961987 \nX - ServiceNow - SysEmail - Version: 2 ";
var newsysid = gre.insert();
var gr = new GlideRecord('sys_email_attachment');
gr.initialize();
gr.attachment = current.sys_id;
gr.file_name = current.file_name.toString();
gr.source = 'notification';
gr.content_disposition = 'attachment';
gr.email = newsysid;
gr.insert();
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 10:39 AM
I am getting really close. I have created a mail script to put the attachment on the sys_email_attachment table and that is working with the exception of getting the Email itself to associate with it.
Any thoughts? Here is my mail script
var gr = new GlideRecord('sys_email_attachment');
gr.initialize();
gr.attachment = current.sys_id;
gr.file_name = current.file_name.toString();
gr.source = 'notification';
gr.content_disposition = 'attachment';
gr.email = ???
gr.insert();
Thanks,
Stacy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2020 12:28 AM
HI,
There is on checkbox on the notification itself called as include attachment. Is that marked as true?
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2020 09:37 AM
This is to send ONLY the attachment that was just attached to the record. In my case I want to send an email to our client when an attachment is attached and only that 1 attachment as they send us attachments and we only want to send those that we attach to the case not everything every time a new attachment is put on.
I have created a before insert Business Rule on the Sys Attachment table.
My condition is the table = sn_customerservice_case and the created by is NOT our integration user. (the one that sends us attachments from the customer).
I had to script the creation of the Notification and the Email Attachment.
(function executeRule(current, previous /*null when async*/ ) {
var fileName = current.file_name;
var tableName = current.table_name;
var tableSysId = current.table_sys_id;
if (tableName == 'sn_customerservice_case') {
var GR = new GlideRecord(tableName + '');
GR.addQuery('account', '8ef1ba261be30890ef6b866fdc4bcbf3');//Only send if this is our particular customer, we don't want this for all accounts.
GR.addNotNullQuery('u_client_case_id');//Only send if this field is true as this means it's an integrated case
GR.addQuery('sys_id', tableSysId + '');
GR.query();
if (GR.next()) {
var caseid = GR.u_client_case_id;
var gre = new GlideRecord('sys_email');
gre.initialize();
gre.mailbox = 'outbox';
gre.state = 'ready';
gre.target = current.sys_id;
gre.subject = "Case ID-" + caseid;
gre.recipients = 'bxxx.admin@xxx.com';
gre.body = "<p>Attached from XXX</p><p></p>";
gre.content_type = "text/html";
gre.headers = "X-ServiceNow-Source:Notification-6fbc13c0dbc41450fd899236db961987 \nX - ServiceNow - SysEmail - Version: 2 ";
var newsysid = gre.insert();
var gr = new GlideRecord('sys_email_attachment');
gr.initialize();
gr.attachment = current.sys_id;
gr.file_name = current.file_name.toString();
gr.source = 'notification';
gr.content_disposition = 'attachment';
gr.email = newsysid;
gr.insert();
}
}
})(current, previous);