Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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,

please allow pop-ups in your browser and it will open each url in new tab and auto-download those files.

It has worked for me.

Regards
Ankur

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

It worked, Thank you!

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

My script is on the Incident table, and I would like to know how we download attachments as filename + user(who attach the attachment)

 

 

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 filename = gr.file_name;
alert(filename);

var created = gr.sys_created_by;
alert(created);

var url = '/sys_attachment.do?sys_id=' + gr.sys_id;
g_navigation.open(url, '_blank');
}
}
}

Hi, this is working to download all attachments on a table, but it seems to only download 1 attachment on records where there are multiple attachments uploaded. Any idea on how to fix this? I've tried "/download_all_attachments.do?sysparm_sys_id=" which is not working in bulk