Mrvs issue with excel sheet.

keshav77
Tera Contributor

Hi All,

 

I am trying to achive to pull the data from excel data sheet to Mrvs. Which I am able to but now I want that   the excel should take the required data in mrvs from row 4 ownward and row 3 is work as header.  like below ss. where row 3 are headers and I am sharing my script script include where I am getting attcahemet. please let me know what changes I need to make in the script to achive this.

 

script include----

getdata: function() {

var id = this.getParameter('sysparm_id');
var obj = [];
var excelid = id;
var parser = new sn_impex.GlideExcelParser();
var attach = new GlideSysAttachment();

var attachmenttest = attach.getContentStream(excelid);
parser.parse(attachmenttest);
while (parser.next()) {
var row = parser.getRow();
obj.push(this.prepareData(row));
}


return JSON.stringify(obj);


},

keshav77_0-1750961084044.png

@Ankur Bawiskar can you help me with this

1 ACCEPTED SOLUTION

Hi,

The lines I have added will skip the first three line. Did you try the script?

Thank you,
Palani

View solution in original post

7 REPLIES 7

yes But I change the header to row 3 it is not working. I pasted mine please have a look if  header is  in row 3 the above data in row  one and two is for just information we not capturing that data.

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@keshav77 

try the approach shared by @palanikumar and let us know the feedback

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

keshav77
Tera Contributor

The code which I am going to share that will work I think As we want 3 row as header -- 

 

getdata: function() {

        var id = this.getParameter('sysparm_id');
        var obj = [];
        var excelid = id;
        var parser = new sn_impex.GlideExcelParser();
        var attach = new GlideSysAttachment();

        var attachmenttest = attach.getContentStream(excelid);
        parser.setHeaderRowNumber(2); // headers are in the third row
        parser.parse(attachmenttest);
        var headers = parser.getColumnHeaders();
        //parser.parse(attachmenttest);


        var rowNum = 0;

        while (parser.next()) {

           
                var row = parser.getRow();
                obj.push(this.prepareData(row));
           

        }
        return JSON.stringify(obj);
    },