Search question - Can you search to see if something has an attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 02:30 PM
I was asked the question today, and I am a new user so I was not sure.
Can you search items in ServiceNow by if they have an attachment or not?
Something like:
attachment == true - return the record in the search
attachment == false - omit the record.
I hope that question makes sense.
Thanks!
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2014 03:56 PM
Not natively, but it is possible to create a new field value and populate it if the record has attachments. Then you could filter on that field value.
Display Whether Tasks Have Attachments in List View - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2014 07:57 AM
This is what we do. We have a field on the task table an use a BR to populate it with the number of attachments. This way it's always there, every record any time you need it!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2014 07:37 AM
Hi Kris,
If what you're looking for is a simpler way to test if a record has attachments or not, you can do so with the hasAttachments() function.
For example, a condition can be built as follows:
current.hasAttachments() && current.state.changes()
Or loop through some records:
//Check for attachments and add link if there are any
var attachment_link = '';
var rec = new GlideRecord('sc_req_item');
rec.addQuery('sys_id', current.request_item);
rec.query();
if(rec.next()){
if(rec.hasAttachments()){
attachment_link = gs.getProperty('glide.servlet.uri') + rec.getLink();
}
}
Reference: GlideRecord - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2014 07:58 AM
we do have something like this and we make use of dynamic filter for this ... I have setup a demo .. Refer this and see if that helps ...
Details:
First, we need a script include to check the records that has attachment and return the id's of the records that has attachment. Next, we need to call the script in the filter of the table needed...
Sample script:
function checkIfRequestHasAttachment()
{
var incidentWithAttachments = [];
var rec = new GlideRecord('incident');
rec.addActiveQuery();
rec.query();
while(rec.next()){
if(rec.hasAttachments()){
incidentWithAttachments.push(rec.sys_id.toString());
}
}
return incidentWithAttachments.toString();
}
Call the script in the filter as below
Demo you can check on
url : demo001.service-now.com/login.do
username and password : admin