MRVS Notification Email Script - Reference variables are not displaying values

matt_ellis
Tera Contributor

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,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

template.print('<table border="0px solid black">');
template.print( "<tr bgcolor='#ddd'align='center'>" );
template.print("<td style='text-align:center' colspan='10'><strong>M/A/C Details</strong></td>");
template.print( "</tr>" );

template.print( "<tr>" );
template.print( "<td><left><b>District</b></left></td>" );
template.print( "<td><left><b>Building</b></left></td>" );
template.print( "<td><left><b>Room #</b></left></td>" );
template.print( "<td><left><b>Employee Name</b></left></td>" );
template.print( "<td><left><b>Current Ext.</b></left></td>" );
template.print( "<td><left><b>New Ext.</b></left></td>" );
template.print( "<td><left><b>IP Phone?</b></left></td>" );
template.print( "<td><left><b>TN-Terminal Number or MAC</b></left></td>" );
template.print( "<td><left><b>Voicemail?</b></left></td>" );
template.print( "<td><left><b>Model</b></left></td>" );
template.print( "<td><left><b>Comments</b></left></td>" );
template.print( "</tr>" );


var mvrs = current.variables.nortel_avaya;
var ritm = current.getUniqueValue();
var rowCount = mvrs.getRowCount();
for (var i = 0; i < rowCount; i++) {
var row = mvrs.getRow(i);
template.print( "<tr>" );
template.print( "<td><left>" +row.select_district.getDisplayValue() + "</left></td>" );
template.print( "<td><left>" +row.building + "</left></td>" );
template.print( "<td><left>" +row.room + "</left></td>" );
template.print( "<td><left>" +row.employee_name + "</left></td>" );
template.print( "<td><left>" +row.current_ext + "</left></td>" );
template.print( "<td><left>" +row.new_ext + "</left></td>" );
template.print( "<td><left>" +row.ip_phone + "</left></td>" );
template.print( "<td><left>" +row.tn_terminal_number + "</left></td>" );
template.print( "<td><left>" +row.voicemail + "</left></td>" );
template.print( "<td><left>" +row.model + "</left></td>" );
template.print( "<td><left>" +row.comments + "</left></td>" );
template.print( "</tr>" );
}
template.print('</table>');

})(current, template, email, email_action, event);

find_real_file.png

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.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

asifnoor
Kilo Patron

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.

 

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank you for your speedy reply Ankur. The query does seem to pull and display the correct info from the table.

You are welcome

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader