- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2016 06:50 AM
Hi folks,
New question about receiving attachments added to the table when responding by email not copied over to other table.
An inbound action is triggered when someone replies to a TASK email. Email body is copied to the TASK Work Notes, which triggers to copy the attachments to another table and close the TASK. When updating the Work Notes manually in the TASK (and adding attachments), the TASK get closed (by business rule) and Attachments are copied over to the other table. Unfortunately this is not working for the inbound action.
Funny detail is when TASK has already attachment, the current attachments are copied over using the inbound action, which looks like the attachments are not fully uploaded when Business Rule to copy attachments is triggered....
Who can help me with this?
Many thanks!
-- Titus
Solved! Go to Solution.
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2016 06:48 AM
Hi Titus,
I guess pasting the script I supplied into the inbound action isn't working...?
In theory it should work with any inbound email action.
What the script should do is update any attachments that are currently linked to the email that is being processed to the target record identified by the inbound action, so in your case a "u_finance_task" record. This should mean that the attachments are linked to this record before your business rule runs (which I guess is the one that then copies/moves the attachments up to the parent table ("u_finance").
If it isn't working you could add some logging, for example:
var sysAttach = new GlideSysAttachment();
var emailSysId = sys_email.getUniqueValue();
gs.log("Email sys_id is: " + emailSysId, "TITUS");
if (emailSysId) {
var sysEmailAttachments = sysAttach.getAttachments("sys_email", emailSysId);
gs.log("Number of attachments found: " + sysEmailAttachments.getRowCount(), "TITUS");
gs.log("Updating attachments to table: " + current.getTableName() + " and sys_id: " + current.getUniqueValue(), "TITUS");
while (sysEmailAttachments.next()) {
sysEmailAttachments.setValue("table_name", current.getTableName());
sysEmailAttachments.setValue("table_sys_id", current.getUniqueValue());
sysEmailAttachments.update();
}
}
After testing just check the System Log->All for messages where source is "TITUS".
Regards,
Nigel

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2019 03:19 AM
Hi,
I found this post while trying to resolve a similar sounding issue but I can't quite get it to work.
Here is my code with comments to explain what I am trying to achieve.
//Requirement is to process an inbound email which has one or more attachments. A record is to be inserted in Table A and then
//a separate record is to be insterted in Table B for each of the attachments with the attachment included
//Target table = Table A - extension of Task
//Table B - also extension of Task contains child records of Table A
// Lookup customer
if (email.from_sys_id) {
if (!customer.get('user', email.from_sys_id)) {
customer.initialize();
customer.user = email.from_sys_id;
customer.insert();
}
}
//Populate Table A record (Table A is the Target Tablle in the Inbound EMail Action)
current.customer = customer.isValidRecord() ? customer.getUniqueValue() : '';
current.from = email.origemail;
current.contact_type = 'email';
current.assignment_group = "NULL";
current.assigned_to = "NULL";
current.short_description = email.subject;
current.description = email.body_text;
current.insert(); //insert into Table A
//Next proceess the email attachments creating a record in table B for each attachment.
//Attach each attachment to its newly created record
var sysAttach = new GlideSysAttachment();
var emailSysId = sys_email.getUniqueValue();
gs.info("Email sys_id is: " + emailSysId);
if (emailSysId) {
var sysEmailAttachments = sysAttach.getAttachments("sys_email", emailSysId);
gs.info("Number of attachments found: " + sysEmailAttachments.getRowCount()); //This returns the correct number of attachments
while (sysEmailAttachments.next()) {
var att = new GlideRecord('Table B'); //Table B
gs.info("Updating attachments to table: " + at.getTableName() + " and sys_id: " + current.getUniqueValue());
att.initialize();
att.parent = current.getUniqueValue();
att.assignment_group = current.assignment_group;
att.short_description = 'Emailed attachment - ' + sysEmailAttachments; // would like to get the name of the attached file here if possible
att.insert();
sysEmailAttachments.setValue('table_name', att.getTableName()); //This is Table B
sysEmailAttachments.setValue('table_sys_id', att.getUniqueValue()); //sys_id of record in table B
sysEmailAttachments.update();
}
}
Thanks for looking.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2021 05:11 AM
A simpler way to handle this in your inbound action would be to use the copy function of GlideSysAttachment. This will copy all attachments to the target and leave the original on the email for recording the source.
// Copy attachments to the target record
GlideSysAttachment.copy("sys_email", sys_email.getUniqueValue(), target.getTableName(), target.getUniqueValue());