How to copy MRVS data to excel sheet after submit the request in portal?

Srinivas Goud K
Tera Contributor

Hi All,

In Custom table after submit the request in portal the data is storing and we have an option called "Export Data" with this option we can download the excel form here all the data is copying in excel sheet but multi row variable set data is not copying how to achieve that any suggestion please thank you.

find_real_file.png

find_real_file.png

The above is custom table after submit the request the data is storing here that's fine.

 find_real_file.png

In the above excel sheet I'm not able to see MRVS data that is not copying in Excel Sheet 

How to resolve this issue any script I have to write? or anything I have to modify please guide me

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Unfortunately you didn't share the UI action script

Regards
Ankur

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

Hello Ankur,

Script:

download();

function download() {
    var varquestion = '';
    var varanswer = '';
    var itemjoin = "";
    var itemquestion = "";
    var itemanswer = '';
    var v;
    var sortedArray = sortVariables(current.variables);
    var a = {
        "RITM NUmber": "ritm",
        "Urgent field": "urgent",
        "New field": "bpp_non_bpp"
    };
    var keys = Object.keys(a).toString().split(",");
    var values = [];
    for (var k = 0; k < keys.length; k++) {
        values.push(a[keys[k]]);
    }
    for (var i in sortedArray) {
        var my_record = current;
        var toPrint = 'Options:\n';
        var qa = new GlideRecord('question_answer');
      // qa.addQuery('table_name', 'x_nooy_gbs_siam_gbs_request');
     //  qa.addQuery('table_sys_id', my_record.sys_id);
        qa.addEncodedQuery('table_name=x_nooy_gbs_siam_gbs_request^table_sys_id='+my_record.sys_id+"^question.type!=5");
        qa.query();
        while (qa.next()) {
            if (qa.value != '') {
                var name = qa.question.name;
                var label = qa.question.question_text;
                var value = my_record.variables[name].getDisplayValue();
                toPrint += ' ' + label + ": " + value + "\n";
                itemquestion += label + "\t";
                itemanswer += value + "\t";

            }
        }
    }

    varquestion += itemquestion + "\t";
    varanswer += "\n" + itemanswer;
    var finaloutput = varquestion + varanswer;

    function sortVariables(variableArray) {
        var sortedVariables = [];
        var count = 0;
        for (var i in variableArray) {
            var object = {
                index: i,
            };
            sortedVariables[count] = object;
            count++;
        }
        sortedVariables.sort(function compare(a, b) {
            return a.order - b.order;
        });
        return sortedVariables;
    }
    var attachfile = new GlideSysAttachment();
    var file = attachfile.write(current, current.number + '.xls', 'test/csv', finaloutput);
    action.setRedirectURL(current);
}