
- 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-06-2020 10:22 AM
I would suggest create an event from an insert business rule created on attachment table(depending on your case requirements).
Then create a notification based on this event.
Please mark my response as correct answer and helpful if it helped solved your question.
-Best Regards
Prateek kumar
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2020 11:44 AM
I need to get the attachment just added to the notification. I don't want to use the 'include attachments' on the notification because that will send all attachments. So how do I tell it to only send the attachment just put on the case?
Thanks,
Stacy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2020 01:42 PM
Create an After insert business rule on sys_attachment table.
Add conditions so that it only triggers for your case table.
Fire an event when the above conditions are evaluated to true.
Based on the event trigger your notification and since your BR is already on attachment table, include the attachment record in one of your parameter from Event
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2020 03:33 PM
My problem there is it is only for a particular account so I don't want it to happen for every attachment on the case table. I can't dot walk in the business rule to build the condition. This seems harder than it should be.