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

asifnoor
Kilo Patron

Hi Sam

Can you check the logs once and see if the control is entering into that 2nd if condition.

gs.include('validators');

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

if (grEmailWatermark.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 "
    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();
  }
}

Hi Asif,

 

Yes it does get into it, but no attachment:

find_real_file.png

Okay, i added the sys_id log.. can you check the output of current.sys_id

Then go to sys_attachment.list and filter by table_sys_id with the value of current.sys_id and check if your find your attachment or not there.

gs.include('validators');

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

if (grEmailWatermark.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 "+current.sys_id+"---taskid: "+grSctask.sys_id);
    grSctask.work_notes = "Forward from: " + email.origemail + "\n\n" + email.body_text;
    GlideSysAttachment.copy("sys_email", current.sys_id, 'sc_task', grSctask.sys_id);
    grSctask.update();
  }
}

Hi Asif,

The sys_id is not picking up correctly

 

find_real_file.png

 

find_real_file.png

Okay,

Try like this and check now if the sys_id is coming correctly now.

gs.include('validators');

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

if (grEmailWatermark.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 "+vSourceID+"---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();
  }
}