The CreatorCon Call for Content is officially open! Get started here.

Shiraz2
Mega Guru

I looked for information on using the Multi Row Variable Set and how can I make use of a script to access the MRVS and its variables. Although there are articles available, I thought I make it an easy read for people here; thus this article.

I am pretty sure there are other ways to do what I did, but this one worked for me very well.

If you like it and use it, please respond accordingly and mark this correct.

See attached and enjoy.

Happy Coding!

Comments
akshayanand6597
Tera Explorer

Its works but still if you want to access without using the multirow variable set name then you can use following method. Let suppose you want to pass all variable of catalog of RITM as object or we can say as key value pair then you can use following code.

 

var ritmSysId ="";//Sys ID of RITM

var result = [];
var arr = [];

 

var ritmSysId = sourceRecord['request_item'] + ""; // Replace with the actual RITM sys_id
var obj = {};
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(ritmSysId)) {
    var vars = ritm.variables.getElements(true);
    for (var i = 0; i < vars.length; i++) {
        if (vars[i].isMultiRow()) {
            var variableValue = vars[i];
            var rows = variableValue.getRows();
            for (var j = 0; j < variableValue.getRowCount(); j++) {
                var row = rows[j];
                var cells = row.getCells();
                var obj2 = {};
                for (var k = 0; k < cells.length; k++) {
                    var cell = cells[k];
                    obj2[cell.getLabel()] = cell.getCellDisplayValue();
                }
                arr.push(obj2);
            }
            obj[vars[i].getLabel()] = arr;
        } else {
            var variableValue = vars[i].getDisplayValue();
        }
        var variableLabel = vars[i].getLabel();
        if ((variableValue != "" && variableLabel != "") && variableLabel != " ") {
            obj[variableLabel + ""] = variableValue; // Add key-value pair to object
        }
        if (variableLabel == " " && variableValue != "") {
            var variableName = vars[i].getName();
            obj[variableName + ""] = variableValue;
        }
    }
}

result.push(obj); // Push the object into the result array
 
 
 
 
If you like it and use it, please respond accordingly and mark this correct.
Version history
Last update:
‎06-05-2019 11:50 AM
Updated by: