- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 05:44 AM
Hi all,
I've been working with this post to display multi-row variable sets in our notifications. Perfect, works great.
However I'm having an issue with one of the row outputs. It's returning the sys_id of the reference field, however I want to instead show the display value of the reference field variable (i.e. the users name).
See below the script I'm using.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Fetch the MRVS data and display them as table in notification
var mrvs = current.variables.jira_confluence_user_details; // MRVS Internal name
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<br<b>Users access is being requested for:</b>");
template.print("<table border =1>");
template.print("<tr>");
template.print("<th>Users Name</th>");
template.print("<th>Users Email</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + row.users_name + "</td>");
template.print("<td>" + row.users_email + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
//This function accept sys_id and table and returns the Display name.
function getName(sys_id,tblName) {
var rec = new GlideRecord(tblName);
if(rec.get(sys_id)) {
return rec.getDisplayValue();
}
}
})(current, template, email, email_action, event);
Which gives me the following output in out notifications.
What do I need to change in the script to display the 'name' field from the referenced user rather than their sys_id?
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 05:52 AM
Hi @LRhodes ,
To display the display value of the reference field (i.e., the user's name) instead of the sys_id, you can modify your script to use the getName function within your loop. The getName function will fetch the display value from the reference field.
Try this modified script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Fetch the MRVS data and display them as table in notification
var mrvs = current.variables.jira_confluence_user_details; // MRVS Internal name
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<br><b>Users access is being requested for:</b>");
template.print("<table border='1'>");
template.print("<tr>");
template.print("<th>Users Name</th>");
template.print("<th>Users Email</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
var userName = getName(row.users_name, 'sys_user');
template.print("<td>" + userName + "</td>");
template.print("<td>" + row.users_email + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
// This function accepts sys_id and table and returns the Display name.
function getName(sys_id, tblName) {
var rec = new GlideRecord(tblName);
if (rec.get(sys_id)) {
return rec.getDisplayValue();
}
return sys_id; // Fallback to sys_id if record not found
}
})(current, template, email, email_action, event);
Thanks.
Hope it helps.
If my response turns useful mark it helpful and accept solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 05:52 AM
Hi @LRhodes ,
To display the display value of the reference field (i.e., the user's name) instead of the sys_id, you can modify your script to use the getName function within your loop. The getName function will fetch the display value from the reference field.
Try this modified script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Fetch the MRVS data and display them as table in notification
var mrvs = current.variables.jira_confluence_user_details; // MRVS Internal name
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<br><b>Users access is being requested for:</b>");
template.print("<table border='1'>");
template.print("<tr>");
template.print("<th>Users Name</th>");
template.print("<th>Users Email</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
var userName = getName(row.users_name, 'sys_user');
template.print("<td>" + userName + "</td>");
template.print("<td>" + row.users_email + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
// This function accepts sys_id and table and returns the Display name.
function getName(sys_id, tblName) {
var rec = new GlideRecord(tblName);
if (rec.get(sys_id)) {
return rec.getDisplayValue();
}
return sys_id; // Fallback to sys_id if record not found
}
})(current, template, email, email_action, event);
Thanks.
Hope it helps.
If my response turns useful mark it helpful and accept solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 06:00 AM
Brilliant - works perfectly. Thank you!