How to get row count of attached excel sheet in catalog form in service now

dell3
Kilo Explorer

How to get row count of attached excel sheet in catalog form in service now

8 REPLIES 8

sachin_namjoshi
Kilo Patron
Kilo Patron

you can write client script and use GlideAjax to calculate attachment count for catalog item.

Record is created for each excel sheet in sys_attachment table.

 

find_real_file.png

 

Regards,

Sachin

dell3
Kilo Explorer

Thanks for Reply!!

Actually my requirement is Count the number of rows in the attached excel sheet on the catalog form.

 

For example:

I attached one excel under that 4 rows data filled.Then auto populated in the variable field as 4.

Kindly help me on the same 

Thanks for Advance.

 

monika223115
Kilo Contributor

Hi Author,

 

Did you find anything on your requirement. I have a similar one.

 

Regards,

Monika Sharma

Hi,

 

Try using something as below in background script once.

var count=0;
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file attachment
var attachmentStream = attachment.getContentStream('6b420a9b2fc454101baee93df699b66a'); //sys_id of record from sys_attachment table
parser.parse(attachmentStream);

//retrieve the column headers
var headers = parser.getColumnHeaders();
var key = headers[0];
var value = headers[1];
while(parser.next()) 
{
count++;
var row = parser.getRow();
//print row value for both columns
//gs.print(row[key] + ': ' + row[value]) ; //Uncomment this to get actual data.
}

gs.print('Number of Rows in excel attached are '+count);

 

Thanks,

Jaspal Singh