- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2014 02:26 AM
I have an Email Client Template that populates the Email Client with text from records on a table [u_stationary_emails]. However, I've realised that the attachments on the records aren't being pulled across to the email client with the text. This is going to pose a huge problem if I can't get the attachment on the record to the email client because I'm using this as a sort of 'stationary/template reply'. Here's what happens in practice:
On my table [u_inbound_mail] I select a 'Stationary Reply' from a Reference field [referencing u_stationary_replies]
Press a button [UI Action] called 'Reply' which opens the Email Client in ServiceNow
The Email Client opens a Client Template
Within the template is the following mail script:
<mail_script> //get the sys id of the referring task var sys_id = current.sys_id; //create a glide record to query the sys_email table for emails sent about this job var emailQuery = new GlideRecord("sys_email"); emailQuery.addQuery("instance",sys_id); emailQuery.orderByDesc("sys_created_on"); emailQuery.query(); var qwer = current.u_stationary_reply.u_body; \\ THIS IS WHATS PULLING ACROSS THE TEXT qwer += "\n"; qwer += current.assignment_group.u_group_signature; qwer += "\n"; qwer += "\n _____________________________________________________"; //Build the originating mail while(emailQuery.next()); { qwer += "\n To:"; qwer += emailQuery.recipients; qwer += "\n From:"; //qwer += emailQuery.user; qwer += current.u_sender; qwer += "\n Sent:"; qwer += emailQuery.sys_created_on; qwer += "\n Subject:"; qwer += emailQuery.subject; qwer += "\n _____________________________________________________"; qwer += "\n\n" qwer += emailQuery.body_text; qwer += "\n"; } template.print(qwer); </mail_script>
So, does anyone know how I can pull the attachment(s) from the u_stationary_email records into this template?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2014 02:36 PM
Hi Wayne,
Here's a potential way forward for you.
I don't have your configuration but have mocked up something similar by sending a mail directly from a Problem record (in your case it would be your u_inbound_mail table) and the mail pulling in attachment/s from a related Change record (could be your u_stationary_replies table).
Step 1. Setup a Business Rule (run before insert) for the sys_email table to fire when a new mail record is created.
Step 2. In the Business Rule Script window, insert a script like below
// Get Task Table and Record variables that fired the email - this is the Problem Table/Record in my mockup
var map = gs.action.getGlideURI().getMap();
var table = map.get('sysparm_table');
var sid = map.get('sysparm_sys_id');
// Query Task Table to locate Record that fired the email
var task = new GlideRecord(table);
task.addQuery('sys_id',sid);
task.query();
// Set related variable to record which contains attachment - in my mockup this is the related Change Record 'rfc' field
while(task.next()) {
related = task.rfc;
// Copy attachment/s from source record to sys_mail record - in my mockup, my source table is the change_request table
GlideSysAttachment.copy('change_request', related, current.getTableName(), current.sys_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2014 09:36 AM
Thanks Tim, that's worked near perfectly. Unfortunately the record has to be saved before the client can be launched and the attachment pulled over, however I've got around this by saving the record if the field is not empty on change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 05:23 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2014 06:24 AM
Hi Wayne,
Building on what Tim wrote, the simplest way would be to add a Business Rule on the sys_email table, and configure it to only trigger for specific cases (else it will fire for all email records).
The following would work for outbound emails from the sc_task table only:
Condition (Insert only):
current.type=='send-ready' && current.target_table=='sc_task'
Script:
GlideSysAttachment.copy(current.target_table, current.instance.sys_id, current.getTableName(), current.sys_id);
Regards,
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 05:25 PM
Hi jake,
How to copy attachments from incident table to sys_email table.
Can you help me with this Include attachment using script .
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2016 12:54 AM
Hi John,
You can create a Before Insert/Update Business Rule as I described in my earlier post with the following details:
Condition (Insert only):
current.type=='send-ready' && current.target_table=='sc_task'
Script:
GlideSysAttachment.copy(current.target_table, current.instance.sys_id, current.getTableName(), current.sys_id);
This will essentially copy the attachments from the related record (in this case a Catalog Task) to the email generated in the sys_email table. You can modify the tables this applies to by changing 'sc_task' to another table of your choice.
I believe a more recent change to ServiceNow was to add the "Include attachments" checkbox on an Email Notification (definition) record. If you check this, it will do the same thing (e.g copy the attachments from the record to the email). Please see below for a screen capture.
Please note that the script you provided a link to in your message, will not copy attachments into an email but rather put hyperlinks into the email body, which point back to the ServiceNow instance so the user can click and download the attachments from ServiceNow rather than their mail server.
Regards,
Jake