- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 11:16 AM
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:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 02:57 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 03:49 PM
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":
Here is a view of the sc_multi_row_question_answer table with that data:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 12:52 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 02:09 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 08:58 AM
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'));
}