How to read and perform operations on the data from an excel attachment on a record.

Dilip Khatri
Kilo Contributor

I need to read all the data from an excel which is in a normal row-column format. Any handy solutions can anyone suggest pls.

1 ACCEPTED SOLUTION

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi Dilip,

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

 

Please mark correct/helpful if applicable.

Regards,

Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.

View solution in original post

1 REPLY 1

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi Dilip,

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

 

Please mark correct/helpful if applicable.

Regards,

Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.