For incoming emails - how do you set the target?

e_wilber
Tera Guru

I am not using a watermark to update an incoming email - I'm actually going through a glide query and updating it that way.

Because of this, the target is empty (even though the email is updating the record). This causes all the attachments on the email to NOT get copied over to the record.

How do I set the current email target to the glide query record?

6 REPLIES 6

You can set the email target using


sys_email.target_table = 'table_name';


sys_email.instance = [object];


danzak
ServiceNow Employee
ServiceNow Employee

There are several mechanisms for determining whether an incoming email is a reply and what it is a reply to. Watermark and subject line can both be used (though watermark is most reliable).



If you are not using either of these mechanisms and your only concern is the attachments, it shouldn't be all that difficult to do. Attachments should be associated to the sys_email you are working on, so you'll be querying the sys_attachment table where the "table_name" is "sys_email" and the "table_sys_id" is "email.getUniqueValue()". Then you'd set those same values to the target table and record instead.



That would look something like:


var attachments = new GlideRecord('sys_attachment');


attachments.addQuery('table_name', 'sys_email');


attachments.addQuery('table_sys_id', sys_email.getUniqueValue());


attachments.query();


while (attachments.next()) {


attachments.setValue('table_name', target.getTableName());


attachments.setValue('table_sys_id', target.getUniqueValue());


attachments.update();


}



Update: I've tested this and it worked for me.