Server Side Script - To export data in to excel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 10:47 PM
Hi,
I am looking for the solution to export Servicenow table columns values into excel using server side script.
Thanks, KB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 11:05 PM
Hi please go through this discussion. This also has the code to export the table as excel.
Mark as helpful if this helps in your solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 11:12 PM
I am looking for the server side script to populate table date into excel where I can read the cell values of excel and do formatting like color and font. Refer the sample file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 11:28 PM
Hi @kailasb
var output = "Number,Company,Short_Description"; //header for csv file
var table = "incident";
var recordId = ""; //using for attachment file
var gr = new GlideRecord(table);
gr.addEncodedQuery("assigned_to=46d44a23a9fe19810012d100cca80666"); //Incident was assigned to Beth Anglin
gr.query();
var count = 0;
while (gr.next()) {
count++;
output += "\n" + gr.number + "," + gr.company.getDisplayValue() + "," + gr.short_description;
if (!recordId) {
recordId = gr.sys_id;
}
}
gs.print(recordId);
writeAttachmentFile(output);
function writeAttachmentFile(data) {
var attachment = new Attachment();
var attachmentRec = attachment.write(table, recordId, "export.csv", "text/csv", data);
}
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 12:38 AM - edited 09-12-2024 12:39 AM