How to display clickable download links for multiple Attachment fields in a ServiceNow report?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Request Number
- CNH/RG: Download attachment
- Reimbursement Letter: Download attachment
- Other Documents: Download attachment
- What is the best approach to display multiple Attachment fields as clickable download links in a ServiceNow report?
- Is it possible to retrieve the attachment sys_id directly from each Attachment field?
- Should I use a Business Rule, calculated fields, Database View, or another solution?
- How can I ensure each report column displays the correct attachment link?
- Is there a recommended approach for handling this in Creator Studio applications?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Hi @saracarvalh,
Yes to your question 2, and that is the key to the whole requirement - and it also explains why your Business Rule fields stay empty.
Why the BR approach failed: uploading a file into an Attachment field creates a record in sys_attachment; it does not update your custom table record, so a Business Rule on your custom table never runs at upload time. Also, a Single Line Text field will not render as a clickable link in a list/report even when it is populated - for clickability the field type matters.
Recommended approach - calculated URL fields (no database view needed):
1. For each Attachment field, the value stored in that field on your record IS the sys_id of the corresponding sys_attachment record. In a script you read it exactly like any other field, for example: current.getValue('u_cnh_rg') returns that attachment's sys_id (empty if no file was uploaded in that field). Because the sys_id comes from the field itself, each column is guaranteed to point at the file uploaded in that field - which answers your question 4 - unlike querying sys_attachment by table_sys_id alone, which cannot tell your three documents apart.
2. Delete the Single Line Text link fields and replace each one with a field of type URL on the same table, set as a calculated field. Use a calculation along these lines for the CNH/RG link (repeat per field with its own field name):
var att = current.getValue('u_cnh_rg');
att ? 'sys_attachment.do?sys_id=' + att : '';
Opening sys_attachment.do?sys_id=<attachment sys_id> downloads/serves that specific file. If you need a forced download from other contexts, the equivalent REST form is /api/now/attachment/<sys_id>/file.
3. Calculated + URL type is what makes it work in the report: the value is always current (including for records created before you added the field, and after a file is replaced - no stale stored URL), empty fields stay empty instead of showing a broken link, and URL fields render as clickable links in list and report output while text fields do not.
4. If you ever do need server logic on upload, put it on sys_attachment (after insert/delete, table_name = your table) or use a Flow triggered on sys_attachment - never on the parent table, for the reason above.
This pattern works the same in Creator Studio / App Engine Studio tables: add the URL fields to the table in the same application scope, then add those URL fields (not the Attachment fields themselves) as the report columns alongside Request Number.
Hope this helps.