Export records to file using flow designer

Sumit25
Tera Contributor

I am trying to create a reusable component which will allow me to export records to either JSON/CSV/EXCEL

How can I authenticate this on behalf of system rather than specific user credentials?

 

function exportTableData(tableName, encodedQuery, fileType) {
    var gr = new GlideRecord(tableName);
    gr.addEncodedQuery(encodedQuery);
    gr.query();
    
    if(gr.getRowCount() > 0) {
        var rm = new sn_ws.RESTMessageV2();
        rm.setHttpMethod('GET');
        var url = gs.getProperty('glide.servlet.uri') + tableName + '_list.do?' + fileType.toUpperCase() + '&sysparm_query=' + encodedQuery + '&sysparm_first_row=1&sysparm_view=';
        rm.setEndpoint(url);
        rm.setBasicAuth('attach_admin','attach_admin');
        var fileName = tableName + '_export.' + fileType.toLowerCase();
        rm.saveResponseBodyAsAttachment(gr.getTableName(), gr.sys_id, fileName);
        return rm.execute();
    }
    return null;
}

// Example usage:
// exportTableData('incident', 'active=true', 'XLSX');

 

 

1 REPLY 1

Anand Kumar P
Giga Patron
Giga Patron

Hi @Sumit25 ,

 

You can create Service Account for each specific integration in sys_user table with UserID as integration user and add roles as rest service and web service role.

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand