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

Mohith Devatte
Tera Sage
Tera Sage

Hello @Srinivas Goud Kadali ,

Can you please share your UI script ?

Hello Mohith,

Below Script I have written

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);
}

Hello @Srinivas Goud Kadali ,

As per the script you are gliding to question_answer table to get the value and label of the variables on the form which is working fine for you 

Bu the reason why MVRS values are not added was MVRS question and answer gets stored in different table but not question answer 

The table is sc_multi_row_question_answer

 var qa = new GlideRecord('question_answer');
        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";

            }
        }
In this glide record you are gliding to question_Answer table 
Please add another glide record to sc_multi_row_question_answer this table and push those label and values like above in same way

Find below screenshot

find_real_file.png

Please mark my answer correct if it helped you

@Srinivas Goud Kadali thanks for marking my answer helpful

if it solved your issue can you please mark my answer correct and close the thread