Direct download attachment field from list on Service Portal

tpeleg
Tera Expert

Hello experts,

 

We are looking for a quick way to to copy the backend functionality to the service portal in case of file attchment field type: auto download file on a list view field when clicking on the file link (not supported oob)

 

 

tpeleg_0-1746383307725.png

 

any suggestions?

 

Thanks,

 

Tomer

 

4 REPLIES 4

mohdarbaz
Kilo Guru

Hi,

Follow the below steps to achieve your requirement.
 
Create a Custom Widget:
Navigate to Service Portal > Widgets and create a new widget.
In the widget's server script, use the spAttachment API to fetch the attachment details.
-Server Script:
var gr = new GlideRecord('sys_attachment');
gr.get($sp.getParameter('sys_id'));
if (gr.isValidRecord()) {
data.attachment = {
      sys_id: gr.getValue('sys_id'),
      file_name: gr.getValue('file_name'),
      content_type: gr.getValue('content_type')
        };
}
 
-Client Script:
function($scope, $http) {
    $scope.downloadAttachment = function(attachment) {
        var url = '/sys_attachment.do?sys_id=' + attachment.sys_id;
        window.location.href = url;
    };
}
 
-HTML Template:
<div>
    <a ng-click="downloadAttachment(data.attachment)">
        {{data.attachment.file_name}}
    </a>
</div>
 
Modify the List View:
Add a column in the list view that uses the custom widget to display the attachment link.
 
Have a look at the below article. Let me know, if you have any more queries.
 
Thanks,
Mohd Arbaz.

 

@tpeleg ,

Thank you for marking my response as helpful.

If my response helped, please mark it correct and close the thread so that it benefits future readers.

 

Regards,

Mohd Arbaz.

Ankur Bawiskar
Tera Patron
Tera Patron

@tpeleg 

you will have to form a link into URL field and keep that field in list view so that once user clicks it will download the file

also check this workaround

List View Download button 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@tpeleg 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader