We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

how to get excel sheet data in mrvs

Vinod S Patil
Tera Contributor

Hello Everyone

I have requirement to add excel sheets data in catalog item's mrvs
I have two sheets in one excel file add and delete.

add sheet has following details:

Action RequestDevice TypeDevice NameSerial NumberFQDNAddressAtlasIP Type
addserverawarepoint-6bd600603514752Atest10.212.105.115FDVC0659924static



delete sheet has following details:

Action RequestDevice TypeDevice NameSerial NumberFQDNAddress
deleteserverSFSFOAM6993188MXL2034JB3sfsfoam6993188.sfo.ca.kp.orgTest






I created script inlcude and onchange client script for it. 
I am getting only first sheet data in mrvs and in second (delete) sheet values are not getting mrvs.

BElow is my script include Please suggest me

getExcelData: function() {
    var arrObj = [];
    var file_id = this.getParameter('sysparam_attSysId');

    var gsa = new GlideSysAttachment();
    var sheetParser = new sn_impex.GlideExcelParser();

    var stream = gsa.getContentStream(file_id);
    sheetParser.parse(stream);

    var sheetNames = sheetParser.getSheetNames();

    for (var i = 0; i < sheetNames.length; i++) {
        var sheetNameRaw = sheetNames[i];
        var sheetName = sheetNameRaw.trim().toLowerCase();
        var action = '';

        if (sheetName === 'add') {
            action = 'add';
        } else if (sheetName === 'delete') {
            action = 'delete';
        } else if (sheetName === 'rename') {
            action = 'rename';
        }

        if (!action) continue;

        // New parser for each sheet
        var streamNew = gsa.getContentStream(file_id);
        var parser = new sn_impex.GlideExcelParser();
        parser.parse(streamNew);
        parser.setSheetName(sheetNameRaw);
        parser.seek(0);

        while (parser.next()) {
            var row = parser.getRow();
            if (!row) continue;

            // Normalize keys
            var normalizedRow = {};
            for (var key in row) {
                if (row.hasOwnProperty(key)) {
                    normalizedRow[key.toLowerCase().trim()] = row[key];
                }
            }

            // Skip empty rows
            var allEmpty = true;
            for (var k in normalizedRow) {
                if (normalizedRow[k]) {
                    allEmpty = false;
                    break;
                }
            }
            if (allEmpty) continue;

            var obj = {};
            obj.action_request = action;

            if (action === 'add' || action === 'delete') {
                obj.device_type = normalizedRow['device type'] || '';
                obj.device_name = normalizedRow['device name'] || '';
                obj.serial_number = normalizedRow['serial number'] || '';
                obj.fqdn_hostname = normalizedRow['fqdn'] || '';
                obj.vlan_network_switch_and_port_info = normalizedRow['address'] || '';
                obj.altas_app = normalizedRow['atlas'] || '';
                obj.ip_type = normalizedRow['ip type'] || '';
            }

            arrObj.push(obj);
        }
    }

    return JSON.stringify(arrObj);
},



t

@Ankur Bawiskar 

5 REPLIES 5

Sanjay191
Kilo Patron

Hi @Vinod S Patil  

can you please provide client script SS what you are passing from the client side?
Thank you 

@Sanjay191 yes have look at client script please 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading)


        return;

    if (!newValue)
        return;

    //g_form.addInfoMessage("Attachment: " + newValue);

        g_form.setLabelOf('excel_file','');


    // Initialize GlideAjax to call the Script Include
    var ga = new GlideAjax('C2CGetApplicationName');

    ga.addParam('sysparm_name', 'getExcelData');
    ga.addParam('sysparam_attSysId', newValue);

    ga.getXMLAnswer(function(response) {

       // g_form.addInfoMessage('second');

        if (!response)
            return;
        // Convert the JSON response string into a JavaScript object
        var data = JSON.parse(response);

        //g_form.addInfoMessage('third');

        g_form.setValue('request_details', JSON.stringify(data));

    });
}

Hi @Vinod S Patil 

did you get in response in data in client or you are not able to set into MRVS  ?

Thank you

Here it is


function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading)


        return;

    if (!newValue)
        return;

    //g_form.addInfoMessage("Attachment: " + newValue);

        g_form.setLabelOf('excel_file','');


    // Initialize GlideAjax to call the Script Include
    var ga = new GlideAjax('C2CGetApplicationName');

    ga.addParam('sysparm_name', 'getExcelData');
    ga.addParam('sysparam_attSysId', newValue);

    ga.getXMLAnswer(function(response) {

       // g_form.addInfoMessage('second');

        if (!response)
            return;
        // Convert the JSON response string into a JavaScript object
        var data = JSON.parse(response);

        //g_form.addInfoMessage('third');

        g_form.setValue('request_details', JSON.stringify(data));

    });
}