MRVS For each, short description using inline script issue.

CandyDee
Kilo Sage

Evening all

 

Was hoping someone may have an answer for this issue I'm facing.

 

I have a cat item with a MRVS. What I'm trying to do is pass the results of each row on the variable set (1st cell)  into a catalogue task short description which I'm doing within flow designer. 

 

I'm using the for each (see screen shots) as this is working fine for all the variables other than one. 

 

1.png

 

I had to use an inline edit on the short description of the task  to retrieve the cell value I'm trying to work with (script below) which retrieves the correct cell value I want. That being the work_instructions which is the name of my variable set and the script is retrieving the correct cell value I need. 

 

2.png

------------

var mrvs = fd_data.trigger.request_item.variables.work_instructions;
var ra2 = fd_data._2__for_each.item.ra2;
var downtime = fd_data._3__look_up_record.record.value;
var install = fd_data._2__for_each.item.downtime_window;

var l = mrvs.getRowCount();
var shortDescription = "";

for (var i = 0; i < l; i++) {
    var row = mrvs.getRow(i);
    var cells = row.getCells();

   
    if (cells.length > 0) {
        shortDescription += cells[0].getCellDisplayValue() + " ";
    }
}

 
var fullShortDescription = "Install " + ra2 + " " + shortDescription + " on " + install + " during " + downtime;

return fullShortDescription;
 
-------------------------------------------------

This issue is that if there is 2 rows see  the below, its combing both the cell values into 1 and because im using a for each its putting them into the same short description if that makes sense. 

 

These are the rows- 

5.png

 

This is the output in the short description on both tasks.

 

6.png

Im trying to put row1 into its own catalog task so should be the value 'REL and TST' into task 1

Then trying to put the row2 into its own catalog task should be the the value 'TST, MST' in this example.

 

Any suggestions would be appreciated. 

 

 

1 ACCEPTED SOLUTION

Hi @CandyDee,

 

I think you would have to iterate the referenced table to get the display value of the records, i.e.

 

var ra2 = fd_data._2__for_each.item.ra2;
var downtime = fd_data._3__look_up_record.record.value;
var install = fd_data._2__for_each.item.downtime_window;

var shortDescription = [];
var refRecord = new GlideRecord('tableName'); //Enter the table name of the referenced table
refRecord.addEncodedQuery('sys_idIN' + fd_data._2__for_each.item.list_variable_name);//replace 'list_variable_name' with the list variable name
refRecord.query();
while(refRecord.next())
{
    shortDescription.push(refRecord.getDisplayValue());
}

var fullShortDescription = "Install " + ra2 + " " + shortDescription.join(',') + " on " + install + " during " + downtime;

return fullShortDescription;

View solution in original post

5 REPLIES 5

CandyDee
Kilo Sage

Master Chun

 

A hat tip and salute to your skill and generosity of time in helping me get this working. I really appreciate it, I doubt I would of figured out that line change. Thank you so much and it works.

 

Have a great easter dude.