Downloading a docx file from binary code file data on browser from ui page button action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 11:11 AM
Hello community ,
I created a Ui page and that Ui page has download button. In the Ui page client script I used glide Ajax and called a function from script include , that script include has a Api call and it returns the binary encoded text data.
I bought this binary encoded data(Ex: W�e(�2�3@Q�w�Z2��) to the Ui page , and now I used blob to convert this binary encoded data to docx , The file is getting downloaded in browser but the content is not displaying , saying could not recognize content. I tried converting the binary code text into base64 value and pass it , but still the data is not appearing in docx file.
So , how to convert a binary encoded data to a docx file without losing the formatting and download it on browser , with a click on UI page.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2025 02:01 AM
Hi @YashwanthKK
To send a ServiceNow attachment to the browser for downloading, you should use the Attachment API, specifically the endpoint that serves the attachment file as a binary stream. This API provides a direct download link for attachments stored in ServiceNow.
The Attachment API endpoint for downloading a file is:
GET /api/now/attachment/{sys_id}/file
Replace {sys_id}
with the Sys ID of the attachment you wish to download. When you access this endpoint (either via REST client, browser, or programmatically), it returns the file as a binary stream with appropriate HTTP headers, prompting the browser to download the file.
Example
If your instance is dev12345.service-now.com
and the attachment Sys ID is 02c7308f40a97200964f0edb17b6d9d0
, the URL would be: https://dev12345.service-now.com/api/now/attachment/02c7308f40a97200964f0edb17b6d9d0/file
Navigating to this URL in a browser (with proper authentication) will initiate the download of the attachment.
Additional Notes:
-
The API returns the file in its original format (e.g., PDF, DOCX, BIN), and the browser handles the download automatically based on the response headers.
-
You can programmatically retrieve the download link using the Attachment API, then present it to users in your UI for direct download.
-
For bulk operations or scripting, you can use tools like
curl
to automate downloads using these URLs
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2025 06:40 AM
what's your actual business requirement?
what are you trying to achieve?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader