Form button to download all attachments for all related records of REQUEST

Praneeth CR
Tera Contributor

can we create a form button on the REQ form that will download anything attached to the REQ, any related RITM and any SC_TASK beneath those RITM 

I have tired with below script in UI action and i can download the attachment from request table or its related RITM or SC_TASK, i cannot download all attachment at once

can anyone help with this issue !

 

gs.setRedirect('/download_all_attachments.do?sysparm_sys_id=' + current.sys_id);
gs.addInfoMessage('hi');
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.sys_id);
gr.query();
while (gr.next()) {

    gs.setRedirect('/download_all_attachments.do?sysparm_sys_id=' + gr.sys_id);

    var grm = new GlideRecord('sc_task');
    grm.addQuery('request', current.sys_id);
    grm.query();
    while (grm.next()) {

        gs.setRedirect('/download_all_attachments.do?sysparm_sys_id=' + grm.sys_id);

    }
}

 

@Ankur Bawiskar @Aman kumar 

Regards

8 REPLIES 8

Mohith Devatte
Tera Sage
Tera Sage

Hey,

Can you please  try using gs.setRedirectURL('')?

Please mark this helpful if it answers your question

Thanks ,

Mohith Devatte.

Hi,

Thanks for your reply. I tried as you said but still facing the same issue. Any other possible ways to achieve it?

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please make your UI action as client side

Client checkbox - True

Onclick - downloadFile()

Script

function downloadFile(){

	var reqUrl = '/download_all_attachments.do?sysparm_sys_id=' + g_form.getUniqueValue();
	g_navigation.open(reqUrl, '_blank');

	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('request', current.sys_id);
	gr.query();
	while (gr.next()) {

		var ritmUrl = '/download_all_attachments.do?sysparm_sys_id=' + gr.sys_id;
		g_navigation.open(ritmUrl, '_blank');
		
		var grm = new GlideRecord('sc_task');
		grm.addQuery('request', current.sys_id);
		grm.query();
		while (grm.next()) {
			var scTaskUrl = '/download_all_attachments.do?sysparm_sys_id=' + grm.sys_id;
			g_navigation.open(scTaskUrl, '_blank');
		}
	}
}

Regards
Ankur

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

Hi @Ankur Bawiskar,

Again facing the same issue that only the request table attachment is getting downloaded. But the requirement of downloading all the attachments from its related ritm and task table isn't working as expected. Referring to one of the already existing thread, i tried using window.open as mentioned by you, but still getting the same result.

 Any other modifications needed? Kindly help!

Regards,