finding MIME file type attachments from sys_attachment table

Sumanth16
Kilo Patron

Can anyone help me with any way to finding  MIME file type attachments from sys_attachment table by using script

2 REPLIES 2

Bhawana Upreti
Tera Guru

Hi Sumanth, 

The attachments that are allowed into Service Now are determined by the System property - security- glide.attachment.extensions - if this property is blank, that means all types of attachments are allowed in the system.

 MIME Types List

In sys_attachment table, we have a field named "content_type" which store the MIME type of the attachment. Now you will have to make a comparison of Content type with the valid mime type with the link mentioned  above.

Below is the script which you have to run on background to get the MIME file type.

 

var attach = new GlideRecord('sys_attachment');
attach.groupBy('table_sys_id');
attach.query();
while(attach.next()){//use `while` if dealing with multiple attachments
      if(attach.getValue('file_name').indexOf('pdf') != -1){//meaning if you can find a file with pdf extension, you can also add multiple conditions using "&&" operator after knowing the property by using above given method.

      gs.print("File Name-- " +attach.file_name+ " Content Type-- "+attach.content_type+" Table Name-- "+attach.table_name+" Table SysID-- "+attach.table_sys_id);
}
}
else {

        gs.print("No file exists with pdf extension");

     }
}

 

If the response is useful, mark the answer correct and helpful. 

Thanks.

 

Ujjawal Vishnoi
Mega Sage
Mega Sage

Hi Sumanth,

 

You can find complete list of MIME type in the link mentioned below.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types

 

The attachments allowed into servicenow are determined by the system property - glide.attachment.extensions - if this property is blank, that means all types of attachments are allowed in the system.

 

In sys_attachment we have a field as content_type which store the mime type of the attachment. Now you will have to make a comparison  of Content type with the valid mime type with the link mentioned  above. For ease purpose you can upload the valid mime type in a custom table to compare by the script in the tool itself.

 

Hope this helps.

 

Regards

Ujjawal