Reference fields in my email script are printing the sysid's instead of the display value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 08:38 AM
Can anyone spot what i am doing wrong with this portion of the my emails script? I have a reference field, i want to print the display value of the field, but its displaying the sysid
Script:
// Check if the value is from the reference field
if (itemVars.sc_item_option.item_option_new.type == '8') {
var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
grRefTable.addQuery('sys_id', mvalue);
grRefTable.query();
if (grRefTable.next()) {
mvalue = grRefTable.getDisplayValue();
}
//updated on 8/27/24
template.print("<td>" + mvalue + "</td>");
template.print("</tr>");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 08:58 AM
@lando321, name is the field name for "Name" in the User table. Typically it should display name if you are indirectly performing GlideRecord on User table if you add "name" in getDisplayValue().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 09:20 AM
Thanks for that explanation, but its still giving me the sysid unfortunately
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 02:44 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 03:20 AM
@lando321 I am but confused with your script.
On the following line you are adding a sys_id filter with mvalue. Assuming mvalue contain the sys_id
grRefTable.addQuery('sys_id', mvalue);
On the following line you are again assigning value to mvalue. Essentially you are overwriting the sys_id value
mvalue = grRefTable.getDisplayValue();
On the following line you are printing the mvalue
template.print("<td>" + mvalue + "</td>");
It looks like your code
var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
grRefTable.addQuery('sys_id', mvalue);
grRefTable.query();
Doesn't return any result due to which the following line always prints a sys_id.
template.print("<td>" + mvalue + "</td>");
Hope this answers your question.