Inbound email action - Issue with Deleting Outlook Signature Images After Copying Attachments

Lokesh5
Tera Contributor

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.


Screenshot 2025-02-16 193741.png

 

 



1 ACCEPTED SOLUTION

Martin Friedel
Mega Sage

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Lokesh5 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Martin Friedel
Mega Sage

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