How to elimiate duplicate attachment in inbound actions

ravichanduk
Mega Expert

Hi i have an req using inbound actions

I sent mail with attachments ( A and B) on other day i sent one more mail with attachments (A and B)

incident was created but attachments should not load it give the previously loaded attachment data 

is it possible if yes can you tell me the way 

or 

any business rule we should create ???????

6 REPLIES 6

Vishal Khandve
Kilo Sage

Hi,

Write a  before BR on attachment table for insert and update.

 

This will not allow to add duplicate attachment for a record.

 

Script:

 

 

 

function onBefore(current, previous) {

 

    var attach = new GlideRecord('sys_attachment');

 

                      attach.addQuery('table_sys_id', current.table_sys_id);

 

                      attach.addQuery('table_name', current.table_name);

 

                      attach.addQuery('file_name', current.file_name);

 

                      attach.addQuery('content_type', current.content_type);

 

                      attach.addQuery('size_bytes', current.size_bytes);

 

                      attach.query();

 

            if(attach.next()){

 

                        current.setAbortAction(true);

 

            }

 

}

That script is doesn't working

HI Vishal Thanks for reply

the given script is working for while we are attach the attachments in incident form

but my question

if i attached with file name as A and created the incident on same other day same file name i attach 

at that time i show and error this file is exist on particular incident table like that

is it possible

write a before insert business rule on sys_attachment table

var attachRec = new GlideRecord("sys_attachment");
attachRec.addQuery("table_name", current.getTableName());
//attachRec.addQuery("table_sys_id", current.sys_id);
attachRec.query();
if (attachRec.next()) {
gs.addErrorMessage("You must attach a complete import template before submitting.");
current.setAbortAction(true);
}

hope it will help you.

thank you