logo

NJP

Delete icon attachments

Import · Nov 19, 2019 · article

I'm pretty sure there are other ways to do this, but my particular client need to not only remove the facebook and twitter icons from inbound emails, but also other images (like company logos, etc), so this was scheduled job set to run a couple of times a day to clean things up.

var removeSmallImages = new GlideRecord('sys_attachment');
removeSmallImages.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^table_name=incident^ORtable_name=interaction^ORtable_name=sc_req_item^content_type=image/png');
removeSmallImages.query();

while(removeSmallImages.next()){
    var fileSize = parseInt(removeSmallImages.size_bytes.getValue());
    if(fileSize < 7500){
        removeSmallImages.deleteRecord();
    }
}

The advantage of this approach is you can set the minimum image size.

View original source

https://www.servicenow.com/community/now-platform-articles/delete-icon-attachments/ta-p/2327255