Populate MRVS Values in RITM Description

jonsr20
Tera Expert

Hello everyone,

 

I have a need to be able to do a global search for MRVS variables. I am not sure if that is possible so a solution I may try is to populate the MRVS variables into the RITM description to enable searching. So far my attempts have failed I created an after update or insert business rule with the condition is the catalog item I want it to function on. Below is the script I am trying to use, I have tried numerous ones from my searches but none seem to work. 

Any Assistance would be greatly appreciated! Or if anyone knows how to global search MRVS that would be even better!

(function executeRule(current, previous /*null when async*/) {

var mrvs_desc = '';
var varMRVS = new GlideRecord('sc_multi_row_question_answer');
varMRVS.addQuery('parent_id', current.sys_id.toString());
varMRVS.orderBy("row_index");
varMRVS.query();

while (varMRVS.next()) {
	var question = varMRVS.getDisplayValue('item_option_new');
	var answer = varMRVS.getValue('value');
	if (question != '' && answer != '') {
		mrvs_desc += question + ': ' + answer + '\r\n';
	}
}
current.description = mrvs_desc;

})(current, previous);
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Jon,

Here's the format I like to use:

var desc = '';
var mrvs = current.variables.refresh_asset_mrvs;
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
	var row = mrvs.getRow(i);
	desc += "Row " + i+1 + " : Name :" + row.var_name + " Number : " + row.var_number + " Description :" + row.var_description + "\n";
}
current.description = desc;

If your MRVS can only be populated/updated when the request is submitted, then run the BR before Insert only.  If it could be updated later and you want the RITM Description to reflect the changes then run the BR before Insert and Update, with a Condition on the Advanced tab or an if statement at the beginning of the script so that it only runs if the MRVS changes.

View solution in original post

4 REPLIES 4

jonsr20
Tera Expert

Tried this also any guidance please! 

var parsed = JSON.parse('refresh_asset_mrvs');

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

{

current.description = "Row "+i+" : Name :" + parsed[i].your_name_variable_backendname + "Number : "+parsed[i].your_number_backend_name+"Description :"+parsed[i].your_description_backend_name+"\n";

}

Brad Bowman
Kilo Patron
Kilo Patron

Hi Jon,

Here's the format I like to use:

var desc = '';
var mrvs = current.variables.refresh_asset_mrvs;
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
	var row = mrvs.getRow(i);
	desc += "Row " + i+1 + " : Name :" + row.var_name + " Number : " + row.var_number + " Description :" + row.var_description + "\n";
}
current.description = desc;

If your MRVS can only be populated/updated when the request is submitted, then run the BR before Insert only.  If it could be updated later and you want the RITM Description to reflect the changes then run the BR before Insert and Update, with a Condition on the Advanced tab or an if statement at the beginning of the script so that it only runs if the MRVS changes.

Thank you so much Brad!

That actually worked perfect, I have the need to search for asset serial numbers entered into the MRVS in the global search. This will accomplish that by inputting the data into the RITM description, I will just add the stage of the flow where assets are updated for the condition, so it updates when all the data is enter! 

 

Thank you,

Jon

You are welcome!