The CreatorCon Call for Content is officially open! Get started here.

Avoid attachments less than 10kb to get attached to incidents received via reply email to servicenow

Debasis Pati
Tera Guru

Hello Everyone,
When servicenow receives emails as reply we have a inbound email action it by default oob attaches the attachments to the target incident/record .
Now we wanted to avoid less than 10kb files to get attached to the target record.
for images to avoid less than 10kb we have oob property "glide.email.inbound.image_sys_attachment.filter.minimum_bytes" but what about other file types how we can avoid that what ever attachments are coming in emails?

@Ankur Bawiskar any suggestions?

Regards,
Debasis

19 REPLIES 19

Hello @Ankur Bawiskar ,
Even i do not write the copy logic it always copies the attachments to the target incident.
also with your advise i have updated my below script but it is copying everything 

gs.include('validators');

if (current.getTableName() == "incident") {

    var gr = current;
    gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
    gr.update();

    // Get attachments from the current email
    var emailAttachments = new GlideRecord('sys_attachment');
    emailAttachments.addQuery('table_name', 'sys_email');
    emailAttachments.addQuery('table_sys_id', email.sys_id);
    emailAttachments.query();

    while (emailAttachments.next()) {
        if (emailAttachments.size_bytes >= 10240) {
            // Copy to incident only if size >= 10 KB
            var attachment = new GlideSysAttachment();
            attachment.copy('sys_email', email.sys_id, 'incident', gr.sys_id);
        } else {
            gs.log("Skipped small attachment: " + emailAttachments.file_name + " (" + emailAttachments.size_bytes + " bytes)");
        }
    }
}


without copying script:
gs.include('validators');

if (current.getTableName() == "incident") {

    var gr = current;
    gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
    gr.update();
}

in both the scenarios attachments are getting copied oob to the target record irrespective of i do write the copy logic in my inbound action.

@Debasis Pati 

then you can use after update business rule on incident table and identify if the comments got changed and starts with reply from:

If yes then iterate and determine which file is less and delete from sys_attachment

OR

Another way is

-> after insert BR on sys_journal_field with condition as this

AnkurBawiskar_0-1760590462042.png

 

-> then iterate sys_attachment and handle the deletion logic

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar ,
Just out of curiosity can i write after business rule on after insert and directly i can put when to run conditions as source as inbound email and attctment.size_bytes less than 10240 and then in script get current.attachment.sysid then glide to attachment table and dete the attchment?
can i do this to achieve?

Hello @Ankur Bawiskar ,
@Ankur Bawiskar ,
Just out of curiosity can i write after business rule on after insert and directly i can put when to run conditions as source as inbound email and attctment.size_bytes less than 10240 and then in script get current.attachment.sysid then glide to attachment table and dete the attchment?
can i do this to achieve?

@Debasis Pati 

Did the approach I shared earlier work for you?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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