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.

Export to CSV with column header labels

priyakumar
Tera Contributor

I was trying to export a report in CSV. Generally when data is exported in CSV the column headers will be the element names(like short_description), but my requirement is to get the column labels as column headers.

Can anyone help me achieve this CSV export?

5 REPLIES 5

Mike Allen
Mega Sage

Maybe a custom processor is what you are looking for.   This will get you started:


Service-now Processors and Platform Development



Hi Mike, Thank you for the info. That was really helpful.


I was trying some code and its not woking.



var rows = [];


var gr = new
GlideRecord('table_name');


  1. gr.query();

// add column headings


for (each e in gr)
row.push(gr.e.getLabel().replace('"',''));


  1. rows.push('"'+row.join('","')+'"\r\n');

while (gr.next()) {


  var row = [];


  for (each e in gr)
row.push(gr.getValue(e).replace('"',''));   // must escape double quotes;

rows.push('"'+row.join('","')+'"');


}


var csv = rows.join('\r\n');



Can you provide me some code I can work it out?


Hello Kumar, were you ever able to get this working? did you apply any other solution.



I have a similar need and would love your input.


Valor1
Giga Guru

You should be able to use this property to control the behavior:

glide.export.csv.column_header_label
 
I can't find a reference to this property on DOCS, so YMMV.