Export Data from Background Script to Excel

DebjitGhosh31
Tera Contributor

Hi,

 

I am currently using a script that stores all duplicate CI serial number in an array. Now my requirement is to export the data stored in the array to an excel file. 

Is there any way I can dump the data from the script to an excel file.

 

Regards,

Debjit

1 ACCEPTED SOLUTION

Hi,
Below is sample code

 

var grX = new GlideRecord("sys_user");//some where we need to save the file here I am attaching on one of the user record logged in one
var csvData="";//This should always be in the 2D array format
//FieldLabel1,FieldLabel2,FieldLabel3,FieldLabel4=====This Row is For Header of CSV
//Val11,Val12,Val13,Val14==== Row 1
//Val21,Val22,Val23,Val24 ==== Row 2
  grX.addQuery('sys_id',gs.getUserID());
  grX.query();
  if(grX.next())
  {
csvHeader="UserID,Name,Company\n";
csvRows1="ABC1,Mario1,SPM1\n";
csvRows2="ABC2,Mario2,SPM2\n";
csvRows3="ABC3,Mario3,SPM3\n";
csvData=csvHeader+csvRows1+csvRows2+csvRows3;
    var grAttachment = new GlideSysAttachment();
    grAttachment.write(grX, "User Details.csv", 'application/csv', csvData);
  }

 

 


Thanks and Regards,

Saurabh Gupta

View solution in original post

11 REPLIES 11

Basheer
Mega Sage

Hi @DebjitGhosh31 

Use below url for example

https://<instance name>.service-now.com/incident_list.do?CSV  ---> This will give you full incidents list

https://<instance name>.service-now.com/incident_list.do?CSV&sysparm_query=sys_id%3E%3Db4aedb520a0a0b1001af10e278657d27   ---> This will give you filtered list

 

For your scenario filter the records and after list.do? and before sysparm enter CSV&. This will export you the data.

 

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Hi @Basheer ,

Thank you for the response.

Although my requirement is to generate XLSX/CSV from a script. I have queried the data and stored in Javascript array and want to export that using a file.

 

Regards,

Debjit