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

Shubham_Jain
Mega Sage

@MaharshiC 

Try to remove "_blank" from the code and try: 

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, '');
win.focus();
}

 

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain


Ankur Bawiskar
Tera Patron
Tera Patron

@MaharshiC 

try this

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, '_self');
win.focus();
}

OR

function onClick(g_form) {
var redirectURL='/nav_to.do?uri=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 ,

 

Thanks for your reply. I tried both the codes but I am facing the same issue. Attachment downloading but the page keeps on loading.

MaharshiC_0-1742823045596.png

 

 

 

@MaharshiC 

did you try with small file size?

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