Export records to file using flow designer
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2024 11:48 AM - edited 12-14-2024 11:53 AM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2024 07:11 PM
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