get value MRVS scripted activity

Nikora
Giga Expert

hello teams,

 

i need some help to retrieve values of my MRVS from scripted activity,

the goal is to prepare a Json files to upload into the RITM,

export files to RITM is OK, export simple variable is ok, but i can't retrieve my mrvs info by IO or name,

mys script below:

 

(function executeRule(current, previous /*null when async*/) {
 
 
var ritmSysId = current.sys_id;
var RITMNumber = current.number;
 
    // Concerned system
  var  system = RITM.variables.v_dc_system;
 
var mrvs = ('IO:7046e0dcdb87ed108d889f5cd39619f8'); //IO du multirow
//var mrvs = JSON.parse(current.variables.multi_test);//array of objects with values
 
 
var rowCount = mrvs.getRowCount();
 
var obj = JSON.parse(mrvs); //The MRVS values are captured as a JSON string, which we parse, creating an array
 
//var volume = RITM.variables.Volume;
//var size = RITM.variables.Size_GB;
var arr=[];
 
for (var i = 0; i < rowCount; i++) { 
var row = mrvs.getRow(i);
arr.push(row.Volume, row.Size_GB);
 
}
    var partitions = JSON.stringify(arr);
 
 
 
 
 
 
 
var sa = new GlideSysAttachment();
 
var document = RITMNumber + " test variables " + system + "\n" + "partitions" + "ARR" + arr + "rowcount" + rowCount;
 
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.get(ritmSysId);
 
sa.write(ritmRec, RITMNumber + "_json.json", "text/csv", document);
 
})(current, previous);
1 ACCEPTED SOLUTION

Thanks a lot for your help, you are a true Guru;)

 

finaly find the way: the good one to get the result espected is

mrvs.orderBy('created');
mrvs.orderBy('row_index');

 

result:

partitions["Volume : RootVG","Size_GB : 32","Volume : SoftVG","Size_GB : 40","Volume : DataVG","Size_GB : 100"]

 

//if i put this : 

mrvs.orderBy('row_index');

mrvs.orderBy('item_option_new');
the result is : 

partitions["Size_GB : 32","Volume : RootVG","Size_GB : 40","Volume : SoftVG","Size_GB : 100","Volume : DataVG"]

 

here my full script if it can help other

(function executeRule(current, previous /*null when async*/) {
	
	var arrjson=[]; //array file
	var ritmSysId = current.sys_id; //sysid RITM
	var RITMNumber = current.number; //Number RITM
	
	var BS = RITM.variables.v_rule_ritm_service.getDisplayValue(); //get BS
	var SDM = RITM.variables.v_gen_approval_user.getDisplayValue(); // get SDM BS
	var user = RITM.variables.v_gen_requested_for.getDisplayValue(); // get Requester
	

	arrjson.push("RITM Number:" + RITMNumber);
	arrjson.push("\n" + "BS:" + BS);
	arrjson.push("\n" + "SDM:" + SDM);
	arrjson.push("\n" + "user:" + user);
    // Concerned system
  var  system = RITM.variables.v_dc_system; //var system
	
	arrjson.push("\n" + "System:" + system);
	

	var mrvs = new GlideRecord('sc_multi_row_question_answer'); //query MRVS

	mrvs.addQuery('parent_id',ritmSysId); //Sysid RITM 
	mrvs.addQuery('variable_set','7046e0dcdb87ed108d889f5cd39619f8'); //IO multirow
	mrvs.orderBy('created');
	//mrvs.orderBy('item_option_new');
	mrvs.orderBy('row_index');  
		

//I used 'row_index' to group the rows together. 'created' might also work
//orderByDesc('row_index') also works if you want to sort by descending instead of ascending
	mrvs.query();
	
	
	var rowCount = mrvs.getRowCount();
	var arr=[];

	while (mrvs.next()) {
   // arr.push(mrvs.getValue('value'));
	arr.push(mrvs.getDisplayValue('item_option_new') + ' : ' + mrvs.getValue('value')); 
    //'item_option_new' is the name for the column labelled 'Question'
						}
				
    var partitions = JSON.stringify(arr);
	
	
	var sa = new GlideSysAttachment();


	var document = arrjson + "\n" + "partitions" + partitions; //Array doc

	var ritmRec = new GlideRecord('sc_req_item');
		ritmRec.get(ritmSysId); //sysID RITM to upload the file

		sa.write(ritmRec, RITMNumber + "_json.json", "text/csv", document); //write doc

})(current, previous);

 

View solution in original post

14 REPLIES 14

Prinssi
Mega Sage

Hi Nikora,

 

The values for MRVS variables are stored in the Multi Row Question Answer table: sc_multi_row_question_answer.

 

You could add a Glide Record on this table by querying the parent_id field for all records with the RITM's sys_id.

Each variable will have its own record, and the records from the same row are grouped by the row_index.

 

To demonstrate, here's a simple MRVS containing two variables: "Question 1" and "Question 2":

pschultz_2-1685054781477.png

 

Here is a view of the sc_multi_row_question_answer table with that data:

pschultz_1-1685054603932.png

Hi Pschultz,

 

thanks, this is the way,

i am now able to get the mrvs linked to the RITM, still one issue, the json.parse doesn't work,

i don't fing how get the value response, where am i wrong please?

 

var mrvs = new GlideRecord('sc_multi_row_question_answer');
 
mrvs.addQuery('parent_id',ritmSysId);
mrvs.addQuery('variable_set','7046e0dcdb87ed108d889f5cd39619f8'); //IO du multirow
mrvs.query();
 
 
var rowCount = mrvs.getRowCount();
 
 
var arr=[];
 
for (var i = 0; i < rowCount; i++) { 
var row = mrvs.getRow(i);
arr.push(row.Value);
 
}

Hi Pschultz,

Thanks this is the way,

i am now able to contact the mrvs linked to the RITM,

but still an issue to get the value, the json.parse is on error when i try to use it, and the value i get from mrvs are null, whera am i wrong please: partitions[null,null,null,null,null,null]ARR,,,,,rowcount6

 

var mrvs = new GlideRecord('sc_multi_row_question_answer');
 
mrvs.addQuery('parent_id',ritmSysId);
mrvs.addQuery('variable_set','7046e0dcdb87ed108d889f5cd39619f8'); //IO du multirow
mrvs.query();
 
 
var rowCount = mrvs.getRowCount();
//var size= "Size_GB";
//var volume= "Volume";
 
var arr=[];
 
for (var i = 0; i < rowCount; i++) { 
 
var row = mrvs.getRow(i);
arr.push(row.Value);
//arr.push(row);
//arr.push(mrvs.row_index.toString());
 
 
}

Hi Nikora,

 

Is there a specific reason for using a for loop instead of while(mrvs.next()) ?

 

The null issue seems to be the use of row.Value instead of row.getValue('value'). One of your values is probably null, but it is being repeated six times.  Chuck does a great job explaining the issue in detail in this video.

 

Here's how I would approach the code:

 

var mrvs = new GlideRecord('sc_multi_row_question_answer');
mrvs.addQuery('parent_id', ritmSysId);
mrvs.addQuery('variable_set', '7046e0dcdb87ed108d889f5cd39619f8'); //IO du multirow
mrvs.query();

var rowCount = mrvs.getRowCount();

var arr=[];

while (mrvs.next()) {
    arr.push(mrvs.getValue('value'));
}