The CreatorCon Call for Content is officially open! Get started here.

How to get MRVS variables data?

KoenSmeulders
Tera Expert

We have a scenario where all HR case/RITM variables are saved in the description. The problem is that MRVS variables are show the same as normal variables. (Hopefuly the list shows you what I mean.)

  • Var1: Value
  • Var2: Value
  • MRVSVar1: Value[0]
  • MRVSVar2: Value[0]
  • MRVSVar1: Value[1]
  • MRVSVar2: Value[1]

Now, I'm trying to get the MRVS data dynamically and turn that in to some better-formatted text. the problem I'm facing is that I can find the MRVS variable, but in a ScopedGlideElement form that seems almost useless. The value is readable, but I can't seem to find a way to use it:

 

 [ { "var1" : "Value1", "var2" : "Value1", "var3" : "Value1" }, { "var1" : "Value2", "var2" : "Value2", "var3" : "Value2" } ] 

It looks readable, but I can't parse it to string or JSON, and when I try to look into the ScopedGlideElement, for getRows() I'll just get 0 and 1, and for getQuestionIds(), I'll just get 0, 1 and 2. I can't seem to find anything useable.

 

Any tips?

 

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

Hi,

Example Script to Format MRVS Data
:

 

-------------------------------------------------------
var mrvsVariable = current.variables.MRVSVar; 
var rows = mrvsVariable.getValue(); 
var formattedText = '';

try {

var parsedRows = JSON.parse(rows);

parsedRows.forEach(function(row, index) {
formattedText += 'Row ' + (index + 1) + ':\n';
for (var key in row) {
if (row.hasOwnProperty(key)) {
formattedText += key + ': ' + row[key] + '\n';
}
}
formattedText += '\n';
});
} catch (e) {
gs.error('Error parsing MRVS data: ' + e.message);
}


gs.log(formattedText);

Try it and do let me know 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

3 REPLIES 3

Ravi Gaurav
Giga Sage
Giga Sage

Hi,

Example Script to Format MRVS Data
:

 

-------------------------------------------------------
var mrvsVariable = current.variables.MRVSVar; 
var rows = mrvsVariable.getValue(); 
var formattedText = '';

try {

var parsedRows = JSON.parse(rows);

parsedRows.forEach(function(row, index) {
formattedText += 'Row ' + (index + 1) + ':\n';
for (var key in row) {
if (row.hasOwnProperty(key)) {
formattedText += key + ': ' + row[key] + '\n';
}
}
formattedText += '\n';
});
} catch (e) {
gs.error('Error parsing MRVS data: ' + e.message);
}


gs.log(formattedText);

Try it and do let me know 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Hello Ravi,

I have one requirement where Amount/ costs are saved in a MRVS column and I want to auto-populate the sum of this amount in another variable. What is the bet way to do it.

Dnyaneshwaree
Mega Sage

Hello @KoenSmeulders,

You can get variable using ".variables" and use "json.parse" and for loop for formatting in your script. Please refer below articles if relatable:
https://www.servicenow.com/community/developer-forum/how-to-get-the-value-of-variables-from-mrvs/m-p...
https://www.servicenow.com/community/itsm-forum/how-to-fetch-the-mrvs-variables/m-p/2679800
https://www.servicenow.com/community/developer-forum/how-to-retrieve-multi-row-variable-set-data-usi...
https://www.servicenow.com/community/now-platform-forum/how-to-get-values-of-multi-row-variable-set-...



Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru