- 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-26-2023 02:18 PM
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"]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 02:27 PM
Did you try with both of these together in this order?
mrvs.orderBy('row_index');
mrvs.orderBy('item_option_new');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 02:36 PM
no i had tried independly, let me try and get the result hopefully, thanks !
- 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-26-2023 12:55 AM
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?