Enhanced Attachments Display in ServiceNow - ben-vargas/servicenow-wiki GitHub Wiki
Attachments often add vital context to ServiceNow records. However, default displays can be limited: attachments may be spread across multiple related records, form views can inherit unintentionally, and default attachment lists aren’t always user-friendly. This article presents strategies to:
- Consolidate attachments from related records into a single list.
- Improve attachment fields for more intuitive navigation and clarity.
- Extend these solutions beyond a single application or record type.
Part 1: Consolidating Related Attachments for Requested Items
Scenario: When working with Requested Items (RITMs) and their associated Catalog Tasks, attachments are often scattered. The goal is to present all relevant attachments in a single related list, eliminating the need to navigate between parent and child records.
Step 1: Create Relationships
Create relationship records that query the Attachment [sys_attachment]
table and consolidate attachments from both the Requested Item and its Catalog Tasks.
-
Navigate to: System Definition > Relationships
-
For Requested Item [sc_req_item]:
- Name: All Attachments
- Applies to table: Requested Item [sc_req_item]
- Queries from table: Attachment [sys_attachment]
- Query with Script:
(function() { var queryString = "table_nameINsc_req_item,sc_task^table_sys_idIN" + parent.getValue("sys_id"); var gr = new GlideRecord("sc_task"); gr.addQuery("request_item", parent.getValue("sys_id")); gr.query(); while (gr.next()) { queryString += "," + gr.getValue("sys_id"); } current.addEncodedQuery(queryString); })();
-
For Catalog Task [sc_task]:
- Name: All Attachments
- Applies to table: Catalog Task [sc_task]
- Queries from table: Attachment [sys_attachment]
- Query with Script:
(function() { var queryString = "table_nameINsc_req_item,sc_task^table_sys_idIN" + parent.getValue("request_item"); var gr = new GlideRecord("sc_task"); gr.addQuery("request_item", parent.getValue("request_item")); gr.query(); while (gr.next()) { queryString += "," + gr.sys_id.toString(); } current.addEncodedQuery(queryString); })();
Step 2: Add the Related List to Forms
- Go to a Requested Item or Catalog Task form.
- Right-click the form header and select Configure > Related Lists.
- Add the All Attachments related list to display consolidated attachments.
Result: Users now see a single, unified list of attachments from both the RITM and its related tasks, simplifying the user experience.
Part 2: Improving Attachment Field Display
Issue: The consolidated related list still shows fields like Table name
and Table sys_id
, which offer little clarity or direct navigation.
Solution: Create a Document ID field (Record
) on the Attachment table to provide a direct link to the source record, making it easier for users to identify and access each attachment’s parent record.
Steps to Implement
-
Add a Document ID Field:
- Navigate to
sys_attachment.list
- Configure Dictionary and add a new field:
- Table: Attachment [sys_attachment]
- Type: Document ID
- Column Label: Record
- Use dependent field: Checked
- Dependent on field: Table name
- Navigate to
-
Populate the Record Field with a Business Rule:
function onBefore(current, previous) { if (current.table_sys_id.changes()) { current.u_record = current.table_sys_id; } }
-
Backfill Existing Records (Optional):
(function() { var gr = new GlideRecord('sys_attachment'); gr.autoSysFields(false); gr.query(); while (gr.next()) { gr.u_record = gr.table_sys_id; gr.update(); } })();
-
Update List Layout: On the “All Attachments” related list, remove
Table name
andTable sys_id
, and add theRecord
field. Users can now click the record link to navigate directly to the attachment’s parent record.
Result: A cleaner, more intuitive attachment list, allowing direct navigation and better context.
Part 3: Generalizing the Approach Across Multiple Applications
Scenario: Beyond Requested Items and Catalog Tasks, organizations might need to apply these improvements to other record types like Incidents, Projects, HR Cases, etc.
Approach:
- Adapt the relationship scripts to query attachments from multiple related records and tables.
- Adjust your Document ID field and Business Rule as needed.
- Update the “All Attachments” related list to cover additional scenarios, from ITSM (Incidents/New Calls) to PPM (Projects/Project Tasks), HR (HR Cases/Tasks), and more.
By adding table-specific logic and relationships, you can create a general “Related Attachments” concept that applies across your instance, consolidating and improving attachment visibility everywhere.
Considerations and Best Practices
-
Testing & Performance:
Always test in a development environment before implementing changes in production. Consider the potential performance impact if you have a large number of attachments. -
Documentation:
Document custom relationships, fields, and Business Rules thoroughly. This ensures that future administrators and developers understand the logic and can maintain it effectively. -
Extensibility:
The methods described here are flexible. Start with a single use case (e.g., RITMs and Catalog Tasks) and scale out to other applications as needed.
Conclusion
By consolidating attachments from related records and refining attachment fields, you provide a clearer, more efficient user experience in ServiceNow. Users gain a single location to view all relevant attachments and can quickly navigate to their sources. Extending these techniques across various applications ensures a cohesive and intuitive attachment management strategy throughout your instance.