Email Client: Add attachments from the incident (or underlying record)

Garrick
ServiceNow Employee
ServiceNow Employee

Anyone have some cleverness up their sleeve to add underlying attachments when using the email client?

For example, if you use the email client from an Incident record that has, say, three attachments, you would have to save these locally, then reattach them in the email client. I'm looking for a selectable way to show the attachments on the email client so that you can avoid this step. I might also only want to choose one, two, of these to attach.

Thanks!

21 REPLIES 21

leslie8
Mega Expert

I have that working in Eureka.



Business Rule


When to run: After Insert Update


Table: Sys Email



function emailClientMessage() {


//Copy attachments from the email client to the target table


GlideSysAttachment.copy("sys_email", current.sys_id, current.target_table, current.instance);
}


Hello Leslie,



I tried your script, it did not seem to work.
here is a copy of my business rule I created, it is also in Eureka


Here is a picture of my When to run tab, And under the Advanced tab I copied your script you provided.
Maybe it is the Order is the problem?




BusinessRule_email.JPG



Possibly could you provide a little more information, as this is definitely something I have been thinking about since I started using Service-now


The code here will copy the email client message and attachments to the associated record activity.



Business Rule


After Insert Update


Table: sys_email


Condition: current.type == 'sent' && current.headers.indexOf('X-ServiceNow-Source: EmailClient') > -1 && current.target_table.indexOf('incident') > -1



Script



emailClientMessage();



function emailClientMessage() {


//Copy attachments from the email client to the target table


GlideSysAttachment.copy("sys_email", current.sys_id, current.target_table, current.instance);


var record = new GlideRecord(current.target_table);


//Grab the email message that matches the record


record.addQuery('sys_id', current.instance);


record.query();


if (record.next()) {


  gs.log("Email Client message sent. Record: " + record.number + "Created by: " + current.sys_created_by + "User: " +current.user);


//Get the client email message that was sent and add it to the work notes


  record.comments = "[code]" + "Email client message sent: " + current.body + "<br />Created by: " + current.sys_created_by +"[/code]";


  record.update();


  }


}


akeppel
Tera Contributor

If I understand the question, this is going the wrong direction.   This script takes attachments sent in the eMail Client and attaches them to the [Incident] record.   What Garrick was looking for was a script that would take attachments from the [Incident] record and add them to the eMail...



Maybe a script that, when you open the eMail Client, automatically attaches all [incident] attachments to the eMail, and then you can just go in and remove the ones you don't want to send.



We have the same ask from our HR group.   It's a pain, when someone sends in a form, for example, for us to have to download the attachment from the record just so we can attach it back into the eMail from our computer.   It seems like there should be a simple solution for adding attachments from the record via the eMail client.


Yogev A_
Giga Contributor

Hi,



I hope this solution will help someone.



This script take attachments from record and add them as link to the Email client Templates.



1. Go to Email --> Client Templates


2. Enter to record - for example "Incident":


find_real_file.png


3. Under field "Body" enter script below:



<mail_script>


var gr = new GlideRecord('sys_attachment');


gr.addQuery('table_sys_id',current.sys_id );


gr.query();


while(gr.next())


{


url = gs.getProperty('glide.servlet.uri') + gs.generateURL(gr.getTableName(), gr.sys_id);


template.print("<a href='" + url + "'>" + gr.file_name + "</a>" +   '\n');


}


</mail_script>



4. result:


find_real_file.png