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

James Chun
Kilo Patron

Hey @CandyDee,

 

Seems like you are iterating the entire MRVS every time.

Is there a reason why you are using the following script to fetch the value?

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

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

Can't you do something like

shortDescription = fd_data._2__for_each.item.variable_name;

 

Is it because that the variable is a GlideList type and you want to get the display value?

 

Cheers

 

 

Morning James

 

Yes, I need the display value not the sys id. 

 

 

also because its a cell and the cell can contain 2 or more individual records from the list collector so it needs the display value of the cell.

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;