Is there any way to find MIME type mismatch files in ServiceNow?

Sumanth16
Kilo Patron

Hi ,

 

In ServiceNow is there any way to find MIME type mismatch files from sys_attachment table by scripting?

7 REPLIES 7

Hi Sumanth,

You can run this script in background script.

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

         gs.print("File Name-- " +attach.file_name+" 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

jbg
Kilo Sage

You might be able to by querying every attachment, then grabbing that attachment, then attaching it to a dummy ticket.

Then to figure out all of the mismatches I found this KB Article in SN Hi KB0657692 that helped me figure out an issue I was having.


FYI, this is a list of all the MIME types, I'm not sure what subset that SN Supports, my guess is that it changes over time.