- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2021 02:42 AM
Hi All,
Please guide on, how i can export data into excel [.xlsx] via script.
Regards,
Suresh.
Solved! Go to Solution.
- Labels:
-
Incident Management
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2021 08:06 AM
we forgot adding the underscore
now it should work fine
g_navigation.open('/' + tableName + '_list.do?EXCEL&sysparm_view=ess', '_blank');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 01:05 PM
Hi Ankur,
The above script is working well but this code works only for CSV.
Is there any solution to get in proper XLS or XLSX format? The attachment is getting inserted, after downloading and opening excel it opens with message as 'file is corrupted or unsafe'
var attachment = new GlideSysAttachment();
var attachmentRec = attachment.write(currentObject, "export.csv", "text/csv", data);
Tried the below formats replacing content_type "text/csv"
xlsx: application/xlsx OR application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xls: application/vnd.ms-excel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 04:11 PM
Were you able to find a solution for this problem? I have been having the same issue and have tried multiple solutions to no avail. here is a snippet of some things i have tried (other solutions are commented out):
var contents = XLSX.writeXLSX(wb, {
bookType: "xlsx",
type: "base64"
});
/**/
var strEncodedString = contents;
var gsUtilGs = gs.base64Decode(strEncodedString);
gs.info(gsUtilGs);
gsUtilGs = gs.base64Encode(gsUtilGs);
var fileName = fname + ".xlsx";
var gr = new GlideRecord('sys_properties');
gr.initialize();
gr.setValue('property_name', 'excel');
gr.insert();
var record_sys_id = gr.sys_id;
var rec = new GlideRecord('sys_properties');
rec.get(record_sys_id);
var contentType = 'application/vnd.ms-excel';
//var contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
var base64Encodedcontent = contents;
var attachment = new GlideSysAttachment();
//var agr = attachment.writeBase64( rec, fileName, contentType, "data:"+ contentType +";base64,"+base64Encodedcontent);
var agr = attachment.write( rec, fileName, contentType, "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,"+base64Encodedcontent);
//var agr = attachment.write( rec, fileName, contentType, gsUtilGs);
//var agr = attachment.write( rec, fileName, contentType, "data:"+ contentType +";base64,"+base64Encodedcontent);
//var agr = attachment.write( rec, fileName, contentType, base64Encodedcontent);
action.setRedirectURL("/sys_attachment.do?sys_id=" + agr);
, the first line uses sheetJS to create the xlsx file essentially, returns the file in base64 string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2021 07:10 AM
Hi,
I have updated in UI Action, but the "on click" action is not working and not getting download . Any other inputs.
Where the same working in background script, which, will show the attachment in sys_attachment table.
Regards,
Suresh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2021 07:44 AM
I would suggest to raise new question as the question for this thread is different and already answered.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 10:32 AM
Hi , I was able to acheive this by bringing to Excel (.xlsx) instead of csv.
Just below copy paste the code, and u will have excel created in the specified record.
Script: