How to get multiple display values from a list collector variable in variableset onto a notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 11:07 PM - edited 08-28-2023 11:17 PM
How to get multiple display values from a list collector variable in a multi-row variable set onto a approver notification. Please help me on this. Thanks in advance.
I haven taken below code as reference.
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 11:47 PM
try this
(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 systemNameArray = [];
var profileNameArray = [];
var approverArray = [];
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);
systemNameArray.push(rec.getDisplayValue());
var rec1 = new GlideRecord('tableReferredByProfileName');
rec1.get(obj[i].profile_name);
profileNameArray.push(rec1.getDisplayValue());
approverArray.push( obj[i].aprovador_do_perfil.toString());
}
template.print('<br/>' + 'System: ' + systemNameArray.toString());
template.print('<br/>' + 'Profile: ' + profileNameArray.toString());
template.print('<br/>' + 'Approver: ' + approverArray.toString());
}
}
)(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 12:40 AM - edited 08-29-2023 12:44 AM
I tried below code as you suggested.
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sysapproval;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
while(record.next()) {
var colorArray = [];
var obj = JSON.parse(record.variables.color_information); //update with your variable set name
for(var i=0; i<obj.length; i++) {
var rec = new GlideRecord('u_demo');
rec.get(obj[i].color_name);
colorArray.push(rec.getDisplayValue());
}
template.print('<br/>' + 'color: ' + colorArray.toString());
If I select single color value, then it is being displayed in the notification.
If I select multiple color values, then it is displaying as blank.
Actually my list collector variable is reference to a custom table(u_demo) and has a reference qualifier(javascript:'u_color=true');
Please help me on this issue.