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.

How to check Excel headers and contents

MiY
Tera Contributor

Hello, I am looking for a new Excel application.
We have a requirement to check the content of an Excel attached to a catalog item in our system.
I would like to parse the Excel attached to the catalog item and check that the correct template is used and that the content is correct.
How should I implement this?

2 REPLIES 2

Sumanth16
Kilo Patron

Hi @MiY ,

 

Best solution is to use GlideExcelParser to play with the data from an excel. 
Please check below link for the entire class and its different methods.

 

https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/GEPS-getRow

 

Adding the sample code for reference.

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]) 
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda