populate mrvs from attached excel

levino
Giga Guru

hI there

 

has anyone tried this, if so let me know if it works, i tried but could not get it to auto-populate

 

https://deepakvednegi.medium.com/bulk-upload-mrvs-f48ab544870f

 

Thanks

Levino

 

1 ACCEPTED SOLUTION

Bhavya11
Kilo Patron

hi @levino ,

 

yes i have tired this before

 

in my requirements i have bills and Amount as two variable in MRVS and attachment type with variable name called upload data

Script include:

 

getXLSBill: function() {
        var arrObj = [];
        var file_id = this.getParameter('sysparam_attSysId');
        var row = '';
        var att = new GlideSysAttachment().getContentStream(file_id);
        var parser = new sn_impex.GlideExcelParser();
        parser.parse(att);
        var headers = parser.getColumnHeaders();
        while (parser.next()) {
            var obj = {};
            row = parser.getRow();
            obj.bills = row[headers[0]]; // first variable 
            obj.amount = row[headers[1]]; // second variable
            arrObj.push(obj);
        }
        return JSON.stringify(arrObj);
    },

 

 on change client script:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    try {
        parseXLS();
    } catch (e) {
        alert("Exception caugght in " + e.message);
    }

    function parseXLS() {
        var att = new GlideAjax('getCallersLocalTime');
        att.addParam('sysparm_name', 'getXLSBill');
        att.addParam('sysparam_attSysId', newValue);
        att.getXML(excelParser);

        function excelParser(response) {
			 var answer = response.responseXML.documentElement.getAttribute('answer');
            g_form.setValue('bill', answer); //bill- name of MRVS
           
        }
    }


}

 

 

Output:

Bhavya11_0-1723800435506.png

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

 

Thanks,

BK

 

View solution in original post

3 REPLIES 3

Bhavya11
Kilo Patron

hi @levino ,

 

yes i have tired this before

 

in my requirements i have bills and Amount as two variable in MRVS and attachment type with variable name called upload data

Script include:

 

getXLSBill: function() {
        var arrObj = [];
        var file_id = this.getParameter('sysparam_attSysId');
        var row = '';
        var att = new GlideSysAttachment().getContentStream(file_id);
        var parser = new sn_impex.GlideExcelParser();
        parser.parse(att);
        var headers = parser.getColumnHeaders();
        while (parser.next()) {
            var obj = {};
            row = parser.getRow();
            obj.bills = row[headers[0]]; // first variable 
            obj.amount = row[headers[1]]; // second variable
            arrObj.push(obj);
        }
        return JSON.stringify(arrObj);
    },

 

 on change client script:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    try {
        parseXLS();
    } catch (e) {
        alert("Exception caugght in " + e.message);
    }

    function parseXLS() {
        var att = new GlideAjax('getCallersLocalTime');
        att.addParam('sysparm_name', 'getXLSBill');
        att.addParam('sysparam_attSysId', newValue);
        att.getXML(excelParser);

        function excelParser(response) {
			 var answer = response.responseXML.documentElement.getAttribute('answer');
            g_form.setValue('bill', answer); //bill- name of MRVS
           
        }
    }


}

 

 

Output:

Bhavya11_0-1723800435506.png

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

 

Thanks,

BK

 

Hi @Bhavya11 

can we validate fields from MRVS suppose x field has decimal values when we are manually adding in MRVS so when user is adding value in excel without decimal and after uploading file it should throw an error like add upto 2 decimal places 

hi @Dipali_Pawar ,

 

You can in script include put the validation .

 

 

Thanks,

BK