- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 07:29 AM - edited 01-22-2025 07:30 AM
Hello!
I was looking for some help with figuring out the lines needed in an email script to display the value of variable in a multi row variable set. This is the code which iam using. Its returning the backend value. I am not able to use the get_display_value().
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 08:12 AM
you won't get it like that
try this
var mrvs = current.variables.stored_items;\\
internal name of MRVS
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<table border =1>");
template.print("<tr>");
template.print("<th>Item</th>");
template.print("<th>Device Type</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
var questionValue1 = ''; // give sysId of the item variable
var dv = new GlideRecord('question_choice');
dv.addQuery('question', questionValue1); // change questionValue with the question's sys_id
dv.addQuery('value', row.item);
dv.query();
if (dv.next()) {
template.print("<td>" + dv.text + "</td>"); // item - internal name of variable (Select Box)
}
var questionValue2 = ''; // give sysId of the device type variable
var dv1 = new GlideRecord('question_choice');
dv1.addQuery('question', questionValue2);
dv1.addQuery('value', row.device_type);
dv1.query();
if (dv1.next()) {
template.print("<td>" + dv1.text + "</td>");
}
template.print("</tr>");
}
template.print("</table>");
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
01-22-2025 08:02 AM
You can get the label of the variable in the variable set with this code:
var now_GR = new GlideRecord('sc_req_item');
now_GR.get('02c38dcd87013300e0ef0cf888cb0bb2');
var vars = now_GR.variables.getElements(true);
for (var i=0; i<vars.length; i++) {
var now_V = vars[i];
if (now_V.isMultiRow()) {
var rows = now_V.getRows();
for (var j=0; j<now_V.getRowCount(); j++) {
var row = rows[j];
var cells = row.getCells();
for (var k=0; k<cells.length; k++) {
var cell = cells[k];
gs.info(cell.getLabel() + ":" + cell.getCellDisplayValue())
}
}
}
}
Let me know if this helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 08:12 AM
you won't get it like that
try this
var mrvs = current.variables.stored_items;\\
internal name of MRVS
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<table border =1>");
template.print("<tr>");
template.print("<th>Item</th>");
template.print("<th>Device Type</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
var questionValue1 = ''; // give sysId of the item variable
var dv = new GlideRecord('question_choice');
dv.addQuery('question', questionValue1); // change questionValue with the question's sys_id
dv.addQuery('value', row.item);
dv.query();
if (dv.next()) {
template.print("<td>" + dv.text + "</td>"); // item - internal name of variable (Select Box)
}
var questionValue2 = ''; // give sysId of the device type variable
var dv1 = new GlideRecord('question_choice');
dv1.addQuery('question', questionValue2);
dv1.addQuery('value', row.device_type);
dv1.query();
if (dv1.next()) {
template.print("<td>" + dv1.text + "</td>");
}
template.print("</tr>");
}
template.print("</table>");
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