Parse excel to feed data in MRVS

Shubhi malaviya
Tera Contributor

Hi Team,

 

We have a catalog item for Bulk Upload of hardware required for new hire. When an excel sheet containing the data is attached to the catalog, every row of the excel should convert into a new row in the MRVS. Every column of the excel will be a variable in the MRVS. 

I used the GlideExcelParser--It is failing with error as shown in the screenshot. I have checked the type of the variable as well and have checked the script line by line. The data is populating in the MRVS correctly but the workflow is errored out. Please assist in this scenario.

 

var count = 0;
var aggroup;
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', current.sys_id);
att.query();
if (att.next()) {
    var imp = new sn_impex.GlideExcelParser();
    var attachment = new GlideSysAttachment();
    var attachmentStream = attachment.getContentStream(att.sys_id.toString());
    imp.parse(attachmentStream);
    var headers = imp.getColumnHeaders();
    var column1 = headers[0]; //column1
    var column2 = headers[1]; //column2
    var column3 = headers[2];
var column4 = headers[3];
var column5 = headers[4];
var column6 =  headers[5];
    
    var newRow = '';
    while (imp.next()) {
        var row = imp.getRow();
        var mrvs = current.variables.bulk_upload_mvrs; //MRVS internal name
        newRow = mrvs.addRow();
 
newRow.u_asset_for = row[column1];
newRow.address = row[column2];
newRow.shortdescription = row[column3];
newRow.u_category_of_product = row[column4];
newRow.computerproduct = row[column5];
newRow.quantity_computerdesktop = row[column6];
 
        count++;
    }
    if (count > 0) {
        gs.addInfoMessage(count + 'Rows added ');
    }
}
S.M
ServiceNow Developer
0 REPLIES 0