- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 05:46 AM
Hi,
I have a MRVS when i called that i get the variable values in JSON format but i get the backend variable name not Question
How to get the question and instead of variable name
in the catalog client script if i try using
alert(g_form.getValue('mrvs_name'));
In server side
gs.info(current.variables.mrvs_name); //from workflow
I get the same output in JSON format
[ { "user" : "b326ee822f1f8890209857892799b6b3", "test2" : "asdf", "test" : "asfd" } ] |
Can anyone please help me how to display the questions ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 08:23 AM
If hardcoding is OK, following script will replace the name with the question. Pass strMrvs to script include.
var columnNames = { // names/question pair of columns in mrvs
'column1': 'Column 1',
'column2': 'Column 2'
};
var mrvsObj = JSON.parse(g_form.getValue('mrvs'));
for (var i = 0; i < mrvsObj.length; i++) {
for (var key in columnNames) {
mrvsObj[i][columnNames[key]] = mrvsObj[i][key];
delete mrvsObj[i][key];
}
}
var strMrvs = JSON.stringify(mrvsObj);
alert(strMrvs);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 06:46 AM
The easiest to to just use the same name as the question but sometimes this is not possbile.
Questions and variables are in sc_item_option table. Query on the 'value' to find the 'question'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 07:24 AM
Can we atleast hard code the questions in scripting like user with User, test2 with Test Application something like that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 07:41 AM
this should help
it would print the key and the value
var obj = [ {
"user" : "b326ee822f1f8890209857892799b6b3",
"test2" : "asdf",
"test" : "asfd"
} ];
var parser = JSON.parse(JSON.stringify(obj));
for(var i=0;i<parser.length;i++){
var obj = parser[i];
for(var key in obj){
gs.info('Key is' + key);
gs.info('Value is' + obj[key]);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 07:47 AM
Hi,
if you want to print the Question Label and the value for that then use this
MRVS data is stored in this table "sc_multi_row_question_answer"
sample script:
var gr = new GlideRecord('sc_multi_row_question_answer');
gr.addQuery('parent_id', current.sys_id);
gr.query();
while(gr.next()){
gs.info('Question label ' + gr.item_option_new.getDisplayValue());
gs.info('Value is ' + gr.value);
}
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader