Remove image/png from inbound emails
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 02:48 PM
Hi Everyone,
I'm currently tasked with setting up a inbound action to map a excel sheet imported to transform maps created in the system. This is working fine but then if someone has a image in their email like in their signature for example the image is getting attached to the email record too. I know there are some properties we can update to help mitigate this but I have been tasked with handling this without changing them. I would like to somehow either create a transform script or business rule to remove any attachment that comes in as image/png in that email before the maps even run but not having any luck accomplishing this. I appreciate any feedback provided thank you in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 03:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 04:20 PM
Hi Nayan,
Thank you for the feedback but I have been tasked with completing this change without modifying those properties. I would like to know alternatives that have been successful for completing this before the properties became an option in previous version upgrade.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 04:55 PM
You can write the below BR in the sys_emal table. Thanks.
Table: sys_emal
When: After
Condition: current.body.indexOf('<img') > 0
Script:
(function executeRule(current, previous /*null when async*/) {
var attachsToDelete = current.body.match(/<img.*alt=".*target_sn".*>/g);
var numToDelete = attachsToDelete.length;
if (numToDelete > 0) {
for (var x = 0; x < numToDelete; x++) {
var sysIdStart = attachsToDelete[x].search(/src="cid:/) + 'src="cid:'.length;
var fileName = attachsToDelete[x].substring(sysIdStart, attachsToDelete[x].search(/@/));
var grSysAttach = new GlideRecord('sys_attachment');
grSysAttach.addQuery('file_name','STARTSWITH', fileName);
grSysAttach.addQuery('table_name', 'sys_email');
grSysAttach.addQuery('table_sys_id', current.sys_id);
grSysAttach.query();
if (grSysAttach.next() && grSysAttach.getRowCount() < 2) {
grSysAttach.deleteRecord();
}
}
}
})(current, previous);
OR Got to the below link-
*************
https://community.servicenow.com/community?id=community_article&sys_id=3208b6c4db114090190dfb243996196c
Regards,
Nayan