Referencing Sysem Variables of a Multi-Row Variable Set (MRVS) in Run Script Code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 06:50 AM
I found this great article here which shows you how to reference the variables you create in a Multi-Row Variable Set (MRVS) in code: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743684
The question is, how can I access the system variables of the MRVS, specifically the records in the Multi-Row Question Answer table (sc_multi_row_question_answer)? I am trying to capture the value of the Row Index field (row_index) and store it somewhere so I can reference that row later in my code.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 07:20 AM - edited 08-07-2023 07:21 AM
Hello @jmiskey ,
First find out the RITM sys_id in Workflow run script, Or create After insert BR on RITM. (*You can use below code in both run script or BR)
var ritmSysID='.....';
var gr = new GlideRecord('sc_multi_row_question_answer');
gr.addQuery('parent_id',ritmSysID);
gr.query();
while(gr.next()){
var rowIndex = gr.getValue('row_index');
gs.info("Row Index" + rowIndex);
// write code here to store row index somewhere
}
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 07:43 AM - edited 08-07-2023 07:46 AM
I don't think that will quite work me (my fault, I should have been more descriptive of what I am doing and how I am trying to use this).
I am using the MRVS to create a bunch of dynamic approvals. Basically, the user will populate the MRVS for as many records as they need, and we have code that iterates through all the records of the MRVS, and creates an approval for each one.
What I am ultimately and then trying to do is that when all approvals are complete, I want to go back to the MRVS and update a "Status" field for each record, indicating whether each line was "Approved" or "Rejected". So I need to tie each approval record that was created with the specific record in the MRVS. I thought I could do this by storing the Row Index field from the MRVS to a custom field we added to the Approver table. But I seem to be unable to capture this value and add it to the code that creates each approval.
Here is the section of my Run Script action that iterates through the MRVS and gathers all the values needed to create each approval. Everything works as it should, except it is not pulling the Row Index value. I tried logging it to see what it would return, and it says "Undefined".
var getRITM = new GlideRecord('sc_req_item');
if (getRITM.get(ritmSysID)) {
//get variables from "entitlement_owner_approvals" MRVS
var myMRVS = JSON.parse(getRITM.variables.entitlement_owner_approvals);
//loop through record and get values from MRVS
for (var i=0; i<myMRVS.length; i++) {
//get values from MRVS record
mOwner = myMRVS[i].owner;
mValue = myMRVS[i].value;
mDesc = myMRVS[i].description;
mAppSysID = myMRVS[i].application_connector;
mRowIdx = myMRVS[i].row_index;
gs.log("Row Index: " + mRowIdx);
//code below create the approval
So that is the challenge I am facing.
Note that by iterating through the rows like I show I above, I get exactly one approval record for each row of my MRVS. By doing a GlideRecord on the Multi-Row Question Answer table like you are showing, I get one record for each field in my MRVS. So if there are 4 rows in my MRVS and 5 Variables, it returns 20 records, instead of the 4 I want.