Inbound Script to remove attachment and add email attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 02:29 PM
Hello Im not used to used inbound actions and have been using the flow designer but for these requirements we do not want to utilize flow designer. I would like to run an inbound action to remove the existing attachments from a data source i already have created and add the attachment from the email. I really need some help on the removal and add here is what i have so far, I gliderecord the datasource using the table and query the sys id of the data source i just need help with removing and adding attachments.
here is my script:
var gr = new GlideRecord('sys_data_source');
gr.addQuery('sys_id', '7d3b210b97e9b91080adb156f053afeb');
gr.query();
if (gr.next()) {
if (gr.hasAttachments()) {
var attachments = new GlideSysAttachment().getAttachments(gr);
for (var i = 0; i < attachments.length; i++) {
var attachment = attachments[i];
var attachmentSysID = attachment.getUniqueValue();
var attachmentName = attachment.getFileName();
//Delete Attachment
if (new GlideSysAttachment().deleteAttachment(attachmentSysID)) {
gs.info('Deleted Attachment:' + attachmentName);
} else {
gs.error('Failed to Delete:' + attachmentName);
}
}
} else {
gs.info("No Attachments found for record.");
}
} else {
gs.error('Record Not Found');
}
getting errors that a proper gliderecord wasnt present when testing out the delete portion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 07:08 PM
Hi @ServNowDev
You are passing glide record to getAttachment s() method, as per the documentation it should be 2 parameters, table name and sys_id of the record.
Try Changing the line,
var attachments = new GlideSysAttachment().getAttachments(gr);
to,
var attachments = new GlideSysAttachment().getAttachments("sys_data_source", "7d3b210b97e9b91080adb156f053afeb");
Please mark my answer helpful and accept as solution if it helped you 👍✅
Anvesh