Strip Email Attachments Inbound Action

wmahmud1
Kilo Explorer

Hello -

I am trying to strip all attachments that get picked up by ServiceNow under 5000 bytes so we can avoid unecessary attachments of users signatures to records.

I have looked at some examples posted already and setup something similar.   My issue is, the business rule on the sys_attachment table seems to run as I can see the script log showing the name of the file being aborted, but the email log itself, is not capturing the target (remains as empty) and not communicating back to the record.   If i turn off this busienss rule, it works fine again.

Any ideas what the issue may be?

(see attached business rule detail)

28 REPLIES 28

poyntzj
Kilo Sage

I found this, or the starters for this on here somewhere, but we have this



in sys_attachment, create a Before Insert Business rule


The condition is


parseInt(current.size_bytes) <= 1800 && current.content_type.toLowerCase().indexOf('image') != -1 && current.table_name.toLowerCase().indexOf('zz_yy') == -1 && current.table_name.toLowerCase() != 'sys_email'



and the script of



current.setAbortAction(true);


//gs.log(current.file_name + ' : insert aborted');



Cheers


Thank you for posting this.   I was looking at stripping the images based on the file names but I was worried about removing a needed attachment.


If you want to be sure, look at the sys_attachment table and using the graphics types look at the typical sizes.


from there you can gauge the normal sizes and change to the code to cover it.


A lot of the attached images are called image???.??? so you could add that as part of the condition



Only feedback we have had is positive as sometimes an engineer would look at a ticket that has had a lot of correspondence and find a lot of image attachments.   This could take a while to locate the relevant image / document they were after.   Now, all the image attachments are gone it is far easier


I found that I had to remove the last part of the condition in my instance to make this work.   .



&& current.table_name.toLowerCase() != 'sys_email'




If I leave that one there, it still attaches the images from the signature. If I remove it, it acts as expected.




I am wondering if I am creating an type of issue by removing it.




-Chris