- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 06:15 AM
Hello All,
I have implemented an Inbound Email Action to copy attachments from email replies to the corresponding engagement record. While this is working as expected, it also copies Outlook signature images (typically less than 18 KB) along with the intended attachments.
To resolve this, I added a script to delete these unwanted signature images after copying. However, the images are not being deleted as expected.
Could you please assist in troubleshooting why the deletion script is not working? Any guidance would be greatly appreciated.
Please refer the attachment for the script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 07:51 AM
Hello,
If you are using GlideSysAttachment, why not to use it also for deleting attachments?
Documentation: GlideSysAttachment - deleteAttachment()
Try to replace code on rows 27-36 with this code:
deleteAttachments(engSysId);
function deleteAttachments(engagement) {
var attachment = new GlideSysAttachment();
var attachmentGR = attachment.getAttachments('sn_audit_engagement', engagement);
while (attachmentGR.next() && (attachmentGR.getValue('size_bytes') < '18000')) {
attachment.deleteAttachment(attachmentGR.getValue('sys_id'));
}
}
Also as Ankur mentioned, condition for 18 kB is not bullet proof.
Tips for an improvement:
- If the Inbound Email Action has Action type: Record Action and it is correctly linked to the record, you don't have to query for Engagement record (rows 4-11) as it is in current object.
- Same applies for querying reply email (rows 13-21) as you already have email object populated.
If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 06:47 AM
is your size query working fine at line 32?
What's the guarantee it's always 18 KB? what if the signature image size changes to 19 or 20KB?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 07:51 AM
Hello,
If you are using GlideSysAttachment, why not to use it also for deleting attachments?
Documentation: GlideSysAttachment - deleteAttachment()
Try to replace code on rows 27-36 with this code:
deleteAttachments(engSysId);
function deleteAttachments(engagement) {
var attachment = new GlideSysAttachment();
var attachmentGR = attachment.getAttachments('sn_audit_engagement', engagement);
while (attachmentGR.next() && (attachmentGR.getValue('size_bytes') < '18000')) {
attachment.deleteAttachment(attachmentGR.getValue('sys_id'));
}
}
Also as Ankur mentioned, condition for 18 kB is not bullet proof.
Tips for an improvement:
- If the Inbound Email Action has Action type: Record Action and it is correctly linked to the record, you don't have to query for Engagement record (rows 4-11) as it is in current object.
- Same applies for querying reply email (rows 13-21) as you already have email object populated.
If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin