- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 05:23 AM
Hi, i am trying to retrieve variables from a Multirow variable set to an approval notification (sysapproval_approver table), but i am have trouble with that, i tried some solutions that i have seen in the forum, but that doesn't work for me. Below the email script that i am trying to use.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sys_id;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
while (record.next()) {
//Note, the value is a JSON string, so we parse it back into an obect to make it easier to work with
var obj = JSON.parse(record.variables.request_information); //update with your variable set name
for(var i=0; i<obj.length; i++) {
template.print('<br/>' + 'System: ' + obj[i].system_name);
template.print('<br/>' + 'Profile: ' + obj[i].profile_name);
template.print('<br/>' + 'Approver: ' + obj[i].aprovador_do_perfil);
// you copy and paste the template.print line and add more variables here
}
}
}
)(current, template, email, email_action, event);
Below what is showing in the notification, its only retrieve the catalog variables and not the multirow that i setup in the mail script
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 09:47 PM
Glad to know.
For that sysId you need to query the table being referred by that variable and then get the display value
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sysapproval;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
if (record.next()) {
var obj = JSON.parse(record.variables.request_information); //update with your variable set name
for(var i=0; i<obj.length; i++) {
var rec = new GlideRecord('tableReferredBySystemName');
rec.get(obj[i].system_name);
var rec1 = new GlideRecord('tableReferredByProfileName');
rec1.get(obj[i].profile_name);
template.print('<br/>' + 'System: ' + rec.getDisplayValue());
template.print('<br/>' + 'Profile: ' + rec1.getDisplayValue());
template.print('<br/>' + 'Approver: ' + obj[i].aprovador_do_perfil);
}
}
}
)(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-01-2022 07:01 AM
gs.info(mrvs)
and let me know what it logs?
Also, please see this article for reference as well.
How to Display Multi Row Variable set (MRVS) data in a notification | Article
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 07:07 AM
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sys_id;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
while (record.next()) {
var mrvs = current.variables.request_information; //update with your variable set name
var objectCount = obj.getRowCount();
for(var i=0; i< objectCount .length; i++) {
var row = mrvs.getRow(i)
template.print('<br/>' + 'System: ' + row.system_name);
template.print('<br/>' + 'Profile: ' + row.profile_name);
template.print('<br/>' + 'Approver: ' + row.aprovador_do_perfil);
}
}
}
)(current, template, email, email_action, event);
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 08:25 AM
Hi,
update as this -> your notification and email script is on sysapproval_approver
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sysapproval;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
if (record.next()) {
var obj = JSON.parse(record.variables.request_information); //update with your variable set name
for(var i=0; i<obj.length; i++) {
template.print('<br/>' + 'System: ' + obj[i].system_name);
template.print('<br/>' + 'Profile: ' + obj[i].profile_name);
template.print('<br/>' + 'Approver: ' + obj[i].aprovador_do_perfil);
}
}
}
)(current, template, email, email_action, event);
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-01-2022 11:55 AM
Hi Ankur, Thanks for this solution,
Its working but for "system_name" and "profile_name" is returning the Sys_ID, any idea how can i get the name for this variables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 09:47 PM
Glad to know.
For that sysId you need to query the table being referred by that variable and then get the display value
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sysapproval;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
if (record.next()) {
var obj = JSON.parse(record.variables.request_information); //update with your variable set name
for(var i=0; i<obj.length; i++) {
var rec = new GlideRecord('tableReferredBySystemName');
rec.get(obj[i].system_name);
var rec1 = new GlideRecord('tableReferredByProfileName');
rec1.get(obj[i].profile_name);
template.print('<br/>' + 'System: ' + rec.getDisplayValue());
template.print('<br/>' + 'Profile: ' + rec1.getDisplayValue());
template.print('<br/>' + 'Approver: ' + obj[i].aprovador_do_perfil);
}
}
}
)(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader