How would i check the extension of an attachment in an inbound action?

Davina
Giga Contributor

I would like an inbound action to check the extension of an attachment to make sure it is .xls otherwise throw an error.

Can i use content_type?

Any help appreciated

1 ACCEPTED SOLUTION

Try this



var getCurrentMail = new GlideRecord('sys_email');


getCurrentMail .get('uid', email.uid);


var emailSYSID = getCurrentMail.sys_id.toString();



var checkAttachment = new GlideRecord('sys_attachment');


checkAttachment.addQuery('table_sys_id', emailSYSID);


checkAttachment.addQuery('file_name','CONTAINS', '.xls');


checkAttachment.query();


if(checkAttachment.next()){


//Email Has Excel


}


else{


  //Email Has No Excel


}


View solution in original post

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

Use the filename column for your query


file_nameLIKE.xls


Thanks for your response... so can you do this within an inbound action like below:



if (email.file_nameLIKE.xls){


  gs.eventQueue("invalid.attachment",current,email.subject, null) ;


  event.state="stop_processing";


}


Let me check and get back to you. I do not think we can get the filename directly using any variable


Try this



var getCurrentMail = new GlideRecord('sys_email');


getCurrentMail .get('uid', email.uid);


var emailSYSID = getCurrentMail.sys_id.toString();



var checkAttachment = new GlideRecord('sys_attachment');


checkAttachment.addQuery('table_sys_id', emailSYSID);


checkAttachment.addQuery('file_name','CONTAINS', '.xls');


checkAttachment.query();


if(checkAttachment.next()){


//Email Has Excel


}


else{


  //Email Has No Excel


}