Download attachment from ui button without redirecting

MaharshiC
Tera Contributor

Hi,

 

I have created the workspace UI action form button. I want to download the attachment from the URL when the user clicks on it but then return to the same workspace form. It is downloading the attachment but then it keeps on loading instead of staying in the same form.

function onClick(g_form) {
var redirectURL='/nav_to.do?uri=sys_attachment.do?sys_id=eb8b1a6f8714e21044e031983cbb35b4';
//top.window.location = redirectURL;
var win = top.window.open(redirectURL, '_blank');
win.focus();
}

 

MaharshiC_0-1742574240102.png

MaharshiC_1-1742574286378.png

 

 

1 ACCEPTED SOLUTION

@MaharshiC 

try this

Also did you check in different browsers? is auto download enabled in browser?

function onClick(g_form) {
var redirectURL='/sys_attachment.do?sys_id=eb8b1a6f8714e21044e031983cbb35b4';
//top.window.location = redirectURL;
open(redirectURL, '_self');
}

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

View solution in original post

8 REPLIES 8

Hi @Ankur Bawiskar ,

Yes it is just an file with 2 rows of records and has only 10kb size

@MaharshiC 

try this

Also did you check in different browsers? is auto download enabled in browser?

function onClick(g_form) {
var redirectURL='/sys_attachment.do?sys_id=eb8b1a6f8714e21044e031983cbb35b4';
//top.window.location = redirectURL;
open(redirectURL, '_self');
}

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

Hi @Ankur Bawiskar,

This code has solved the issue. Thank you.

 

@MaharshiC 

Glad to help.

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