- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2024 11:57 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2024 12:57 AM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2024 12:57 AM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 09:08 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2024 01:03 AM
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-...
Thank you!!
Dnyaneshwaree Satpute
Tera Guru