How to read Excel header row server-side in ServiceNow?

Med99
Tera Contributor

We want to validate the header row of an uploaded Excel file server-side before processing the import, to make sure the right template was used.

GlideExcelParser is not defined in Transform Map scripts or Scripts-Background. Any other way to do this? Thanks

 

1 REPLY 1

Tanushree Maiti
Tera Patron

 

OOB GlideExcelParser()  can only validate excel column header.

Refer Servicenow Documentation: GlideExcelParser - Scoped, Global 

 

Try this code:

var parser = new sn_impex.GlideExcelParser(); 
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream(<attachment sys id>);

parser.parse(attachmentStream); 

//retrieve the column headers
var headers = parser.getColumnHeaders();  
var header1 = headers[0]; 
var header2 = headers[1]; 

//print headers
gs.info(header1 + " " + header2); 

while(parser.next()) { 
  var row = parser.getRow(); 
  //print row value for both columns   
  gs.info(row[header1] + ' ' + row[header2]) 
}

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti