How to display clickable download links for multiple Attachment fields in a ServiceNow report?

saracarvalh
Tera Contributor
I'm working on an application developed in ServiceNow Creator Studio, using the custom table 
The application has a form with multiple Attachment fields, each representing a different document, such as CNH/RG, reimbursement letter, and other required documents.
My requirement is to display a separate, clickable download link for each attachment directly in a ServiceNow report.
For example, the report should have the following columns:
  • Request Number
  • CNH/RG: Download attachment
  • Reimbursement Letter: Download attachment
  • Other Documents: Download attachment
Each link must download the specific file associated with that Attachment field.
What I've tried:
I created corresponding Single Line Text fields to store the attachment URLs and implemented a Business Rule to generate the links using the attachment sys_id.
However, the link fields remain empty, even though the attachments are successfully uploaded and visible in the form.
My questions are:
  1. What is the best approach to display multiple Attachment fields as clickable download links in a ServiceNow report?
  2. Is it possible to retrieve the attachment sys_id directly from each Attachment field?
  3. Should I use a Business Rule, calculated fields, Database View, or another solution?
  4. How can I ensure each report column displays the correct attachment link?
  5. Is there a recommended approach for handling this in Creator Studio applications?
 
1 REPLY 1

kmohammed
Tera Guru

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.