Email attachment not getting attached with inbound action

Sam198
Mega Guru

Hi all,

I have an inbound action where it was initially sent from the ticket but the receiver fwd it back to us, the below inbound action picks that up and adds it to the initial ticket, however the attachment is not getting attach, i am using the GlideSysAttachment.copy function but it does not attach the attachment.

 

gs.include('validators');

var grEmailWatermark = new GlideRecord('sys_watermark');
grEmailWatermark.addQuery("number", email.body.ref);
grEmailWatermark.query();

if (grEmailWatermark.next()) {
var vSourceID = grEmailWatermark.source_id;
var grSctask = new GlideRecord('sc_task');
grSctask.addQuery("sys_id", vSourceID);
grSctask.query();

if (grSctask.next()) {
grSctask.work_notes = "Forward from: " + email.origemail + "\n\n" + email.body_text;
GlideSysAttachment.copy("sys_email", current.sys_id, current.target_table, current.instance);

grSctask.update();
}
}

11 REPLIES 11

It gives this - but different to Table sys_id

find_real_file.png

Okay, check this.

1. Go to sys_attachment.list and check the latest attachment and check the table_sys_id and table name.

Is it linked to sys_email or any other table.

2. After that try this code and check the logs once.

gs.include('validators');

var grEmailWatermark = new GlideRecord('sys_watermark');
grEmailWatermark.addQuery("number", email.body.ref);
grEmailWatermark.query();

if (grEmailWatermark.next()) {
  var email_log = new GlideRecord('sys_email'); // eg: what does this line do
  email_log.addQuery('uid', email.uid);
  email_log.orderByDesc('sys_created_on');
  email_log.query();
  if(email_log.next()) {
    gs.log("Entered into 1st if condition");
    var vSourceID = grEmailWatermark.source_id;
    var grSctask = new GlideRecord('sc_task');
    grSctask.addQuery("sys_id", vSourceID);
    grSctask.query();
    if (grSctask.next()) {
      gs.log("Entered into the 2nd Table Emaillog sys id"+email_log.sys_id+"---taskid: "+grSctask.sys_id);
      grSctask.work_notes = "Forward from: " + email.origemail + "\n\n" + email.body_text;
      GlideSysAttachment.copy("sys_email", vSourceID, 'sc_task', grSctask.sys_id);
      grSctask.update();
    }
  }
}