Trigger excel export via script include

Andre27
Tera Contributor

Hi all,

how can I trigger an export similiar to "List context menu -> Export -> Excel (.xlsx)" by scoped script include?

I can use the functionality "List context menu -> Export -> Excel (.xlsx)" to export a list in the backend of course and get an entry in table sys_attachment with the export file included. But I like to trigger it via script include.

Is there any API to use?

Thanks Andre

1 ACCEPTED SOLUTION

Pratiksha Kalam
Kilo Sage

Hi Andre,

Go through below link will definitely help you,

https://community.servicenow.com/community?id=community_question&sys_id=4d42c7addb98dbc01dcaf3231f96...

If my reply helps you at all, I’d really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click both the Helpful and Accepted Solution buttons!

 

Regards,

Pratiksha

 

 

View solution in original post

2 REPLIES 2

Pratiksha Kalam
Kilo Sage

Hi Andre,

Go through below link will definitely help you,

https://community.servicenow.com/community?id=community_question&sys_id=4d42c7addb98dbc01dcaf3231f96...

If my reply helps you at all, I’d really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click both the Helpful and Accepted Solution buttons!

 

Regards,

Pratiksha

 

 

sayali udgave
Kilo Guru

Hi,

 

Try this:

 

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);

 

}

 

 

Thanks

Sayali