Add "Download All Attachments" button on ticket form in Service Portal

Chris17
Tera Contributor

Hello,

I currently have a requirement to configure a button that allows for downloading all attachments added within in a ticket form on the Service Portal, see photo below

find_real_file.png

I know where to make these edits, but as to how I am unsure and inexperienced within the Service Portal. Any ideas?

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

Hu, never looked into this before but there is a button on the platform UI Attachments dialog to download all attachments.  This is the function the button calls.

function downloadAllAttachments() {
    var downloadUrl = window.location.protocol + '//' + window.location.host + '/download_all_attachments.do?sysparm_sys_id=' + attachmentParentSysId
        + "&sysparm_this_url=" + getCurrentPageURL();
    window.location = downloadUrl;
}

 

So it looks like you can just add a button to your widget and then open a new tab/window to the above URL and you are all set.

View solution in original post

10 REPLIES 10

DrewW
Mega Sage
Mega Sage

Hu, never looked into this before but there is a button on the platform UI Attachments dialog to download all attachments.  This is the function the button calls.

function downloadAllAttachments() {
    var downloadUrl = window.location.protocol + '//' + window.location.host + '/download_all_attachments.do?sysparm_sys_id=' + attachmentParentSysId
        + "&sysparm_this_url=" + getCurrentPageURL();
    window.location = downloadUrl;
}

 

So it looks like you can just add a button to your widget and then open a new tab/window to the above URL and you are all set.

Chris17
Tera Contributor

Hi there Drew,

Thank you, this helps a lot! How would I configure the button? How would ServiceNow know when the button is clicked to trigger the function? Sorry I'm very new to this.

 

Thanks!

You are going to have to update the widget and add a button.  Its very similar to any web page, there is an onClick event but since its Angular you us ng-click.

To find out which widget to update you can ctrl+right click on the area you want the button to get a menu and you select "Widget in Editor".  There is probably an example of a button or other onclick in there

If you don't know anything about AngularJS at all I would suggest you go out to Udemy and signup for one of there AngularJS classes.  I learned a lot from the one I took.

 

Chris17
Tera Contributor

Hi Drew,

I followed your instruction and have added a button, see below

find_real_file.png

As for the actual functionality, I added the function you provided earlier into the client script section of the widget form, yet when I click it nothing happens. Any ideas?

 

find_real_file.png

find_real_file.png