How to copy/print MRVS (Multi row variable set) values to catalog task release management?

keshav77
Tera Contributor

Hi Community,

My catalog item contains MRVS which contains reference (application to select), list collector. How do we copy these values selected onto the release management work notes? 

Tricky part is, Each row with different reference variable selected will create a catalog task per row . There can be multiple tasks generated. And that catalog task description should contain only that row variable values.

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Here's the method I like to use in a Workflow Run Script or Business Rule to retrieve the MRVS data and loop through the contents.  Since this is a JSON string, I don't think you can use getDisplayValue or dot-walk, so you'll need to do a GlideRecord to lookup the reference and list sys_ids.  If you have one MRVS variable named cmdb_name that is a reference to the cmdb_ci table, and one MRVS variable named users that is a list collector referencing the sys_user table, here is one way to get values other than sys_ids to a work note:

var tes = current.variables.cmdb_basic_tes; //MRVS internal name
var totalRows = tes.getRowCount();
for (var i = 0; i < totalRows; i++) {
    gs.info('test');
    var row = tes.getRow(i);
    var cmdbGR = new GlideRecord('cmdb_ci'); //reference variable table
    if (cmdbGr.get(row.cmdb_name)) { //mrvs reference variable name
        gs.info('test2');
        var name1 = cmdbGR.name; //field from reference table to display in work note
    }
    var usrArr = [];
    var usrGR = new GlideRecord('sys_user'); //list collector variable list table
    usrGR.addQuery('sys_id', 'IN', row.users); //mrvs list collector variable name
    usrGR.query();
    while (usrGR.next()) {
        gs.info('test2');
        usrArr.push(usrGR.user_name); //field on list table to display in work notes
    }
    current.work_notes=name1+'||'+usrArr.join(', ');
}

This would add a work note for each row of the MRVS.

 

var appl = current.variables.application_information;
var totalRows = appl.getRowCount();
 
for (var i = 0; i < totalRows; i++) {
 
 gs.info('test');
 var appi[];
    var row = appl.getRow(i);
    var cmdbGR = new GlideRecord('cmdb_ci'); //reference variable table
    cmdbGR.addQuery('sys_id', 'IN', row.applications) { 
        cmdbGR.query();
    while (cmdbGR.next()) {
        gs.info('test2');
        appi.push(cmdbGR.name); //field on list table to display in work notes
    }
    var ap[];
    var row = appl.getRow(i);
    var cmdbGR1 = new GlideRecord('u_cmdb_busapp_instance'); //reference variable table
    cmdbGR1.addQuery('sys_id', 'IN', row.bai)  
        cmdbGR1.query();
    while (cmdbGR1.next()) {
        gs.info('test2');
        ap.push(cmdbGR1.name); //field on list table to display in work notes
}
var na[];
    var row = appl.getRow(i);
    var cmdbGR2 = new GlideRecord('sn_vul_app_scanned_application'); //reference variable table
    cmdbGR2.addQuery('sys_id', 'IN', row.name1)  
        cmdbGR2.query();
    while (cmdbGR2.next()) {
        gs.info('test2');
        ap.push(cmdbGR2.name); //field on list table to display in work notes
}
var notes = appi.join(',')+'.'+ap.join(',')+','+na.join(',');
current.work_notes=notes;
 
not getting called for me in worknotes

Which logs are you receiving?  Add more, with script variable names, and make sure the logs are unique so that you can see what is happening in the script - how far it is getting, values stored in script variables, records returned in GlideRecord queries,...

Mani A
Tera Guru

In workflow

    var mrvsData = current.variables.u_mrvs;

    if (mrvsData) {

        var x= JSON.parse(mrvsData);

        for (var i = 0; i < x.length; i++) {

            var row = x[i];

           Var gr= new GlideRecord( tableName);

gr.get(row.u_application)

var y= gr.name ;

var tsk=new GlideRecord ( 'sc_task');

tsk.intialize();

task.descrption=y;

task.insert();

      }

    }