How to export attachments of multiple records at once

Jessica1307
Tera Expert

I want to download some attachement of multiple records at once, Is this possible?

1 ACCEPTED SOLUTION

try this

function downloadAll() {
    var selectedSysIds = g_list.getChecked();
    var arr = selectedSysIds.split(',');
    for (var i = 0; i < arr.length; i++) {
        alert(arr[i]);
        var gr = new GlideRecord("sys_attachment");
        gr.addQuery("table_sys_id", arr[i]);
        gr.query();
        if (gr.next()) {
            alert(123);
            var url = '/sys_attachment.do?sys_id=' + gr.sys_id;
            g_navigation.open(url, '_blank');            
        }
    }
}

Regards
Ankur

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

View solution in original post

19 REPLIES 19

Hi , I followed the steps above to create the ui page, but how to test it? I don't see there is any difference.

Jessica1307
Tera Expert

@Ankur Bawiskar ,  can you help me with this?

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

multiple records of same table right?

why not create list choice UI action and iterate over all the sysIds and download it

I shared solution for something similar 3 years ago but that is not required in your case

****I want to download selected files from incident instead of all could you please help with the s...

For your case you can use something similar

1) List choice - True

2) Client - True

3) Onclick - downloadAll()

4) Script

function downloadAll() {
	var selectedSysIds = g_list.getChecked();
	var arr = selectedSysIds.split(',');
	for (var i=0; i< arr.length;i++)
	{
		var gr = new GlideRecord("sys_attachment");
		gr.addQuery("table_sys_id", arr[i]);
		gr.query();
		if (gr.next()) {
			window.open('/sys_attachment.do?sys_id='+gr.sys_id,"_blank");
		}
	}
}

find_real_file.png

Regards
Ankur

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

Hi, I used your method, But there is no ui action show in my incident list, Is there something wrong? find_real_file.png

find_real_file.png

Hi,

you select the records using the checkbox and then at the bottom you will find it

find_real_file.png

Regards
Ankur

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