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

here the result with : mrvs.orderBy('item_option_new');

 

it is a nonsense.

 

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

Did you try with both of these together in this order?

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

 

no i had tried independly, let me try and get the result hopefully, thanks !

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);

 

Nikora
Giga Expert

Thanks Pschultz,

 

this is the way, 

i am now able to get the mrvs linked to the RITM, still on issue to get the value of the mrvs,

the json.parse doesn't work, i have try with row.Value but not working, 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);
 
}