Validate the excel template automatically, when the user submits the request. Validate if it has the columns as mentioned

mahfooz1
Tera Contributor

On submitting the request after attaching the attachment, if user has attached file other that xlsx format then request should not be submitted.
Also, if user has attached xlsx file then Validate the excel template automatically, when the user submits the request. Validate if it has the columns as mentioned.

Deepak Ingale1
Mega Sage

Hi,

 

You can use the GlideExcelParser class to read the content of EXCEL file

https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=GEPS-GlideExcelParser

 

Note: Please mark reply as correct if it has answered your question or mark it as helpful if you found reply as helpful

AbhishekGardade
Tera Sage

Hello Mahfooz,

Below is the code for Fetching Contents from Excel File

var parser = new sn_impex.GlideExcelParser();

var attachment = new GlideSysAttachment();

// use attachment sys id of an excel file attachment

var attachmentStream = attachment.getContentStream('f18e8e0a1b2f3300364d32a3cc4bcb99');

parser.parse(attachmentStream);

//retrieve the column headers

var headers = parser.getColumnHeaders();

var key = headers[0];

var value = headers[1];

//var obj = {};

while(parser.next()) {

                        var row = parser.getRow();

                        //print row value for both columns

                        gs.log(row[key] + ': ' + row[value]) ;

               //         obj[row[key]] = row[value];

}

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Hi Abhishek

Can you help me in solving the below requiremnt as you mentioned above 

please help me in suggesting the code to do it

i had source field names shown below

when i try to attach the excel sheet with different header name the transform map should not insert data to my target table 

Can you suggest me the code 

 the values of headers are not matching with source field names

so it should not allow to run transform

 

Thank You

Shashank 

 

 

Hi Abhishek,

After fetching value from excel, can we check that value in a table.