Is there a way to identify the attachments in Email notification?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 07:23 AM
Sys_email table contains the list of emails sent or received in an instance. Do we have any method to find the number of records which have attachments in it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 11:26 PM
Harish,
We are trying the other way around. This script would give the number of attachments in sys_email table. We look for the number of emails with attachments.
Thanks,
Sowmiya M

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 11:41 PM
Hi,
you need to write before(insert & update) BR in Incident table for that.
and in script section use below code.
var gr= new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id",current.sys_id);
gr.query();
current.u_attach_number=gr.getRowCount();
Mark correct or helpful if it helps you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 12:17 AM
Hi Sowmiya,
Then you may use background script as below but it would take longer for exeution unless you specifiy a conditon like created in last week or something.
var count = new GlideAggregate('syslog_email');
count.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');//replace with query of last 7 days or something for a quick result
count.addAggregate('COUNT','email');
count.query();
while(count.next()){
var getrecord= count.email;
var getognumber=new GlideRecord('sys_email');
getognumber.addQuery('sys_id',count.email);
getognumber.query();
while(getognumber.next())
{
var numberis= count.getAggregate('COUNT','email');
gs.print("there are currently "+ numberis +" attachments for mail with subject:"+ getognumber.subject+' & target record as '+getognumber.instance);
}
}
Also, if this would be required in future as well then I suggest you to create a new field on sys_email table (Has Attachments) & it should be marked as true by a business rule when an entry for it is made in syslog_email table with Message containing keyword as 'Attachment:'
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.