catalog item variable reference field values not displaying the display value in email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 11:49 PM - edited 06-30-2025 11:51 PM
i am trying to display the catalog item variable and its values in the email body using an email script. however reference field values not displaying the display value in email and instead only the sys id is filled. how to solve this ?
var ritm = new GlideRecord('sc_req_item');
if (current.sysapproval.sys_class_name == 'sc_req_item') {
ritm.get(current.sysapproval.sys_id);
}
if (ritm.isValidRecord()) {
template.print('<h3>Catalog Item Variables</h3>');
template.print('<table border="1" cellpadding="5" cellspacing="0">');
template.print('<tr><th>Variable</th><th>Value</th></tr>');
var varMtom = new GlideRecord('sc_item_option_mtom');
varMtom.addQuery('request_item', ritm.sys_id);
varMtom.query();
var hasVariables = false;
while (varMtom.next()) {
var varOption = varMtom.sc_item_option.getRefRecord();
if (!varOption) continue;
var rawValue = varOption.getValue('value');
if (!rawValue) continue; // skip empty
var varDef = varOption.getElement('item_option_new').getRefRecord();
if (!varDef) continue;
var varLabel = varDef.getValue('question_text') || varDef.getValue('label') || 'Label not found';
var displayValue = rawValue;
// Force type to integer
var varType = parseInt(varDef.getValue('type'), 10);
// Resolve reference field values properly
if (varType === 7 && varDef.getValue('reference')) { // Type 7 = reference
var refGR = new GlideRecord(varDef.getValue('reference'));
if (refGR.get(rawValue)) {
displayValue = refGR.getDisplayValue();
}
}
hasVariables = true;
template.print('<tr><td><strong>' + varLabel + '</strong></td><td>' + displayValue + '</td></tr>');
}
template.print('</table>');
if (!hasVariables) {
template.print('<p>No variables provided or all were empty.</p>');
}
} else {
template.print('<p>Requested Item not found.</p>');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:17 AM
Hi @Ravivarman Saee
Reference type variable value is 8 not 7.
Modify that and try again.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:20 AM - edited 07-01-2025 12:22 AM
script looks fine to me with 1 change, query with value 8 instead of 7 for Reference type variable
Did you add logs and see if table name came fine which you are using in GlideRecord?
the table being referred has any field marked as Display=True at dictionary level?
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
07-01-2025 12:52 AM
I thought of using your solution from Solved: Approval Email Display RITM Ticket Variables - Fol... - ServiceNow Community.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:59 AM
is your script working fine now?
If yes then please close the thread by marking appropriate response as correct.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader