Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copying ServiceNow Outputs to an Excel

Priyobroto Roy1
Tera Contributor

Java script code to export data (Outputs) from ServiceNow instance and copy it to an excel sheet.

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Priyobroto Roy1 Please refer to this thread https://www.servicenow.com/community/developer-articles/generate-csv-file-through-script/ta-p/231977... to know the steps to generate a CSV file via script.

anvesh_v
Giga Guru

Please use the following script as per your need 
var attachment = new GlideSysAttachment(); /

/set up inputs var rec = new GlideRecord('incident');

rec.get('78271e1347c12200e0ef563dbb9a7109');

var fileName = 'example.txt'; var contentType = 'text/csv';

var content = 'The text that is stored inside my file'; var agr = attachment.write(rec, fileName, contentType, content); gs.info('The attachment sys_id is: ' + agr);


var gr1 = new GlideRecord('incident'); // Respective table where you want to store the temp FILE CSV
gr1.get('sys_id');

 csvData  = csvData + '"' + your headers + '"' + '\t';
csvData = csvData + '" "\t';  // Please loop For loops as per requirement 
 
var grAttachment = new GlideSysAttachment();
grAttachment.write(gr1, fileName, 'application/csv', csvData);

ServiceNow URL for Reference https://developer.servicenow.com/dev.do#!/reference/api/xanadu/server/no-namespace/c_GlideSysAttachm...

Please let me know if the answer is helpful