- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 11:23 AM
Good Day everyone,
I created this email script to read the information from my MRV to be added to the email notification.
However, in my MRV i have three reference fields that when i submit the form will only display their sys_id.
How do i get to display their actual values on the email script.
here is the code i am using:
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sys_id;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
while (record.next()) {
var obj = JSON.parse(record.variables.bill_to_office_mrv);//mvr name
for (var k = 0; k < obj.length; k++) {
' + obj[k].office_office + ' - ' + obj[k].department_office.getDisplayValue() + ' //Office & Department field you see in the pic above
' + obj[k].gl_code_office + ' // gl code
}
}
i tried using the .getDisplayedValue() on the department and it comes back with undefined.
any help is appricated here
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 01:09 PM
Oke no worries, I thought lets spend 5 minutes before bedtime 😅
I just modified the example slightly, works immediately on Catalog Item. You just need to replace the MRVS name and place the logic of your HTML table since I just used an example of building the description field.
var current = new GlideRecord('sc_req_item');
current.get('da8fa1bd479f29100692249bd36d43f5');
///
var description = [];
var mrvs = current.variables.mobile_devices_set;
var l = mrvs.getRowCount();
for(var i = 0; i < l; i++) {
var row = mrvs.getRow(i);
var cells = row.getCells();
var m = cells.length;
for(var j = 0; j < m; j++) {
description.push(cells[j].getLabel() + ': ' + cells[j].getCellDisplayValue());
}
if(i < l) {
description.push('');
}
}
gs.info(description);
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 01:02 PM
Yes i realize that, been deep in this all day and my brain is kinda fried

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 01:09 PM
Oke no worries, I thought lets spend 5 minutes before bedtime 😅
I just modified the example slightly, works immediately on Catalog Item. You just need to replace the MRVS name and place the logic of your HTML table since I just used an example of building the description field.
var current = new GlideRecord('sc_req_item');
current.get('da8fa1bd479f29100692249bd36d43f5');
///
var description = [];
var mrvs = current.variables.mobile_devices_set;
var l = mrvs.getRowCount();
for(var i = 0; i < l; i++) {
var row = mrvs.getRow(i);
var cells = row.getCells();
var m = cells.length;
for(var j = 0; j < m; j++) {
description.push(cells[j].getLabel() + ': ' + cells[j].getCellDisplayValue());
}
if(i < l) {
description.push('');
}
}
gs.info(description);
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 06:18 AM
haha thank you very much, i used that as a template to apply it onto my enviornment and was able to make it all work
Thank you once again for spending the 5 extra minutes and have a great day
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 12:17 PM
Hi Peter,
Hope so you're doing well,
Hello,
In your email script, you are attempting to display the actual values of the reference fields from your MRV (Multi-Row Variable) table. However, you are encountering an issue with the .getDisplayValue() method returning undefined for the department field.
To resolve this, you can try modifying your code as follows:
var record = new GlideRecord('sc_req_item');
var sysCurrentRecordSysId = current.sys_id;
record.addQuery('sys_id', sysCurrentRecordSysId);
record.query();
while (record.next()) {
var obj = JSON.parse(record.variables.bill_to_office_mrv); // MRV name
for (var k = 0; k < obj.length; k++) {
var officeDisplayValue = obj[k].office_office.getDisplayValue(); // Get display value of the office field
var departmentDisplayValue = obj[k].department_office.getDisplayValue(); // Get display value of the department field
var glCode = obj[k].gl_code_office; // GL code
// Use the obtained display values and gl code in your email content as needed
}
}
By directly assigning the display values to separate variables (officeDisplayValue and departmentDisplayValue), you can ensure that the .getDisplayValue() method is called correctly and retrieve the actual values for the respective fields. You can then use these variables in your email script to display the desired information.
Remember to adjust the email content to include these variables as per your requirements.
Hope so this will work for you!
Regards,
Bryce June
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 12:28 PM
Thank you for the reply but i am still only getting undefined