Attachment - Inbound Email Action

Gaurav Kumar15
Giga Guru

Hi All,

 

We are creating Incidents via the Inbound Email Actions. So, whenever an email contains attachment that gets attached to the Incident which got created from that mail. So, can anyone tell me that if we don't want to attach that on the incident from inbound email, then how can we do that.

 

We are using calgary.

 

TIA

19 REPLIES 19

Hello,

 

Hope you are doing well. Does this also work for attachments added from an incoming email?

 

Thanks,

Sharan

ghaynie
Kilo Explorer

Try adding this:


void disableAttachments()




See: GlideForm (g form) - ServiceNow Wiki




VaranAwesomenow
Mega Sage

Hi, I have found a easier way of doing this.



I have created a business rule on sys_attachment table



When -> After


Insert


Update


Table Name = 'table name'



Advanced



Script that does the check and deletion of the attachment record



Logic Used :


syslog table captures details of the EMAIL record that has created the attachment and the name of the attachment.


sys_email table captures details of the in bound email and the target(instance) record reference.



I am trying to find out the latest email record that has created the attachment, in order to get that I run a glide record on sys_email where target(instance) = table sys id field from sys_attachment table


Once I get the sys id of the sys_email record, I build the source text which follows below convention.


EMAIL.sys_id


Message contains imagename.



if the syslog matches the email record for the attachment record table sys id, then attachment will be deleted.


################CODE START#########################



(function executeRule(current, previous /*null when async*/) {


     


      // Add your code here


     


      var email_log = new GlideRecord('syslog');


      var email = new GlideRecord('sys_email');


      email.addQuery('instance',current.table_sys_id);


      email.orderByDesc('sys_created_on');


      email.query();


      var email_sys_id ='';


      var email_text;


      var imagename = current.file_name;


      if(email.next())


              {


              email_sys_id = email.sys_id;


      }


      email_text = 'EMAIL'+'.'+email_sys_id;


     


     


      email_log.addQuery('source','CONTAINS', email_text);


      email_log.addQuery('message','CONTAINS',imagename);


      email_log.query();


      if(email_log.next())


              {


              current.deleteRecord();


      }


     


      gs.log("email_text "+ email_text + "imagename"+ imagename + "Email_log" + email_log.sys_id);


     


     


     


})(current, previous);



################CODE END#########################


I did a script to prevent just logos from emails getting attached to records.


I have created a business rule on sys_attachment table


When -> Before


Insert


File Name contains 'image'


Advanced


Script that does the check and deletion of the attachment record



Logic Used :


syslog table captures details of the EMAIL record that has created the attachment and the name of the attachment.


sys_email table captures details of the in bound email and the target(instance) record reference.




I am trying to find out the latest email record that has created the attachment, in order to get that I run a glide record on sys_email where target(instance) = table sys id field from sys_attachment table


Once I get the sys id of the sys_email record, I build the source text which follows below convention.


EMAIL.sys_id


Message contains imagename.




if the syslog matches the email record for the attachment record table sys id, then attachment will be deleted.


################CODE START#########################


(function executeRule(current, previous /*null when async*/) {




  var email_log = new GlideRecord('syslog');


  var email = new GlideRecord('sys_email');


  email.addQuery('instance',current.table_sys_id);


  email.orderByDesc('sys_created_on');


  email.query();


  var email_sys_id ='';


  var email_text = '';


  var imagename = current.file_name;


  if(email.next())


          {


          email_sys_id = email.sys_id;


  }


  email_text = 'EMAIL'+'.'+email_sys_id;


  email_log.addQuery('source','CONTAINS', email_text);


  email_log.addQuery('message','CONTAINS',imagename);


  email_log.query();


  if(email_log.next())


  {


        current.setAbortAction(true);


  }







})(current, previous);


################CODE END#########################


Thanks for sharing! One finding is that this business rule will also delete any attachment added in a scheduled report. Where I tested in a non prod, I found those regular scheduled reports with pdf were being sent without their attachments.