- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2020 06:39 AM
Hello!
I was looking for some help with figuring out the lines needed in an email script to display the value of a reference variable in a multi row variable set. The two variables in question are 'select_district' and 'building'.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, template.print('<table border="0px solid black">'); template.print( "<tr>" );
})(current, template, email, email_action, event); |
When .getDisplayValue is added, it returns as undefined. When left as 'building' is, it returns the sys ID instead of the reference value. Any help with this would be greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2020 08:56 AM
Hi,
you cannot use getDisplayValue() here
you need to query those 2 tables with that sys_id and get the display value and then print
var gr = new GlideRecord('district table'); // give proper table name here
gr.addQuery('sys_id', row.select_district);
gr.query();
if(gr.next()){
template.print( "<td><left>" +gr.name + "</left></td>" ); // give here the field on district table which stores name
}
var gr = new GlideRecord('building_table'); // give proper table name here
gr.addQuery('sys_id', row.building);
gr.query();
if(gr.next()){
template.print( "<td><left>" +gr.name+ "</left></td>" ); // give here the field on building table which stores name
}
Mark as Correct Answer & Helpful if this solves your issue or Helpful if this is useful to you.
Regards
Anukr
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-09-2020 08:44 AM
Hi,
getDisplayValue can be used if the field is a reference field.
So for select_district, check what is the data type? If its a reference then check if the value exists in the select_district field or not by removing getDisplayValue
And for building, since it is showing sys_id, check if its a reference field or not. If its a reference field, then add .getDisplayValue and you will get the value instead of sys_id.
Mark the comment as a correct answer and helpful if this answers your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2020 08:56 AM
Hi,
you cannot use getDisplayValue() here
you need to query those 2 tables with that sys_id and get the display value and then print
var gr = new GlideRecord('district table'); // give proper table name here
gr.addQuery('sys_id', row.select_district);
gr.query();
if(gr.next()){
template.print( "<td><left>" +gr.name + "</left></td>" ); // give here the field on district table which stores name
}
var gr = new GlideRecord('building_table'); // give proper table name here
gr.addQuery('sys_id', row.building);
gr.query();
if(gr.next()){
template.print( "<td><left>" +gr.name+ "</left></td>" ); // give here the field on building table which stores name
}
Mark as Correct Answer & Helpful if this solves your issue or Helpful if this is useful to you.
Regards
Anukr
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-09-2020 10:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2020 11:05 PM
You are welcome
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader