We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to list all incidents that have attachments in ServiceNow?

vickythakur
Kilo Explorer

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?

1 ACCEPTED SOLUTION

surajsengar
Kilo Guru

@vickythakur 

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);

    }}

View solution in original post

2 REPLIES 2

Dr Atul G- LNG
Tera Patron

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:

  1. Navigate to sys_attachment.list
  2. In the Table name column, add *incident to filter where table name contains incident.
  3. 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]

****************************************************************************************************************

surajsengar
Kilo Guru

@vickythakur 

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);

    }}