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.

Searching attachment in ServiceNow

Alex Litvak
Tera Contributor

Hello Community Members!

 

We are seeking a way to programmatically search attachments (Excel type) in Change Request applications based on specific keywords. I’m wondering if this is possible.

 

Any assistance in this matter would be greatly appreciated.

 

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi @Alex Litvak ,

 

Please refer to the below article:

https://www.servicenow.com/community/developer-articles/reading-attachment-contents-copying-attachme...

 

GlideExcelParser()

Creates an instance of GlideExcelParser.

The API name space identifier "sn_impex" must be used when creating a GlideExcelParser object.

 

Example

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

View solution in original post

1 REPLY 1

Sumanth16
Kilo Patron

Hi @Alex Litvak ,

 

Please refer to the below article:

https://www.servicenow.com/community/developer-articles/reading-attachment-contents-copying-attachme...

 

GlideExcelParser()

Creates an instance of GlideExcelParser.

The API name space identifier "sn_impex" must be used when creating a GlideExcelParser object.

 

Example

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