- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hello Community,
I want to query all incidents and display only those that have attachments. Could someone guide me on the best way to achieve this in ServiceNow?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
var inc = new GlideRecord('incident');inc.query();
while (inc.next()) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id', inc.sys_id);
attach.addQuery('table_name', 'incident');
attach.query();
if (attach.hasNext()) {
gs.print("Incident with attachment: " + inc.number);
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
HI @vickythakur
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0829927
Instructions
If you're working from a baseline instance with demo data, simply navigate to:
<your_instance>.service-now.com/incident_list.do?sysparm_query=sys_idIN8d6353eac0a8016400d8a125ca14fc1f%2C9d385017c611228701d22104cc95c371%2C47064b68a9fe19810186793eefffc9b7%2Cd71da88ac0a801670061eabfe4b28f77%2Cd71f7935c0a8016700802b64c67c11c6%2C471d4732a9fe198100affbf655e59172%2Ca9e428cac61122760075710592216c58%2C47204688a9fe1981011a20af100f381a%2Cd71b3b41c0a8016700a8ef040791e72a
You can find these records with the following steps:
- Navigate to sys_attachment.list
- In the Table name column, add *incident to filter where table name contains incident.
- The 'Table SysID' column shows the sys_id of target records which have the attachment(s).
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
var inc = new GlideRecord('incident');inc.query();
while (inc.next()) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id', inc.sys_id);
attach.addQuery('table_name', 'incident');
attach.query();
if (attach.hasNext()) {
gs.print("Incident with attachment: " + inc.number);
}}

