I want to add attachment from email to target table (directly to paper-clip) using inbound or script include?

chsandi
Kilo Contributor

I want to add attachment from email to target table (directly to paper-clip) using inbound or script include? can yoy plz suggest on this. Its an urgent requirement

7 REPLIES 7

Hi Ashutosh,

 

Thanks for the reply.

Requirement is not to attach from record to record.

need to attach from mail to record.

Thanks in advance

 

currently i am using this code

Script include

var SERReadingEmail = Class.create();
SERReadingEmail.prototype = {
checkMail: function(){
var gr = new GlideRecord('incident');
gr.description = email.body_text;
gr.short_description = email.subject;
gr.contact_type = "email";
gr.caller_id= gs.getUserID();
gr.u_affected_contact = gs.getUserID();
gr.opened_by= email.user_id;
gr.no_attachment=email.attach;

var supportKeywords = ["support", "assistance", "access"];
//var incidentKeywords = ["incident", "assistance", "ticket"];
var emailBody = email.body_text.toLowerCase();
var emailSubject = email.subject.toLowerCase();

for (var j=0; j< supportKeywords.length; j++) {

if((emailBody.indexOf(supportKeywords[j]) > -1 )|| (emailSubject.indexOf(supportKeywords[j]) > -1)){
//gr.insert();
Recipients = "";
}


}
},
type: 'SERReadingEmail'
};

 

 

Inbound action

 

//var keywords = new SERReadingEmail(current).checkMail();


var gr2 = new GlideRecord('sys_user');
//gr2.addQuery('user_name',gs.getUserID());
gr2.query();
if(gr2.next())
{
var diocese = gr2.department.name.getDisplayValue();
if(gs.getUserID().isMemberOf(diocese="Customer Support"))
{
var keywords = new SERReadingEmail(current).checkMail();
}
else
{
gs.log('state ignored');
//email.state = "ignored";
var gr = new GlideRecord('sys_email');
gr.query();
if (gr.next()) {
gs.log('state entered');
//gr.mailbox.name = "skipped";
// gr.setDisplayValue('state')= "ignored";
gr.setValue('state','ignored');
// gr.type = "received-ignored";
//gr.state = "ignored";
gs.log(" state>>>" + gr.state);
gs.log(" type>>>" + gr.type);
gs.log(" mailbox>>>" + gr.mailbox);
gr.update();

}
}
}

/*if (sys_email.hasAttachments()){
var att = new GlideRecord("sys_attachment");
att.addEncodedQuery("table_name=sys_email^table_sys_id=" + sys_email.getValue("sys_id"));
att.query();
while (att.next()){
att.table_name = "incident";
att.table_sys_id = gr.getValue("sys_id");
att.update();
}
}*/

 

here i have to add the code for attachments either in inbound or script include

HI,

Whenever you create a new Incident from email inbound action, if email has attachment OOB they will get attach to Incident. So you don't have to worry about it.

 

If its a old incident then you will have to fetch the incident number and then copy attachment to it.

 

Thanks,
Ashutosh Munot

Hi,

 

I can give you one more solution is to write a business rule on sys_email table.

Condition will be on change of Target field. 

 

Here you will have to fetch the sys_id from target field and check its class is incident. If yes then use below thing to copy attachment to incident:

 

GlideSysAttachment.copy('sys_email',current.sys_id,'incident',current.instance);

Thanks,
Ashutosh Munot

Mark helpful or correct.