MRV email Script returning SYS_ID from the reference fields

Peter Williams
Kilo Sage

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.

 

PeterWilliams_0-1686248465805.png

 

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

1 ACCEPTED SOLUTION

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

LinkedIn

View solution in original post

17 REPLIES 17

I am almost there, so far i have the Office and departments working

But now the date in the first field is getting undefined and the GL Codes is still showing as undefined.

 

PeterWilliams_0-1686254289905.png

 



for (var k = 0; k < obj.length; k++) {
var grLoc = new GlideRecord('cmn_location');
grLoc.addQuery('sys_id', obj[k].office_office);
grLoc.query();
while (grLoc.next()) {
var officeDisplayValue1 = grLoc.name;
}
var grDep = new GlideRecord('cmn_department');
grDep.addQuery('sys_id', obj[k].department_office);
grDep.query();
while (grDep.next()) {
var departmentDisplayValue1 = grDep.name;
}

var grGl = new GlideRecord('u_gl_codes');
grGl.addQuery('sys_id', obj[k].gl_code_office);
grGl.query();
while (grDep.next()) {
var glCode1 = grGl.u_gl_long_desc;
}

found the issue

while (grDep.next()) { 

should be

while (grGl.next()) { 

 

however the date in the first one is now displaying as Undefined but the second one is fine

PeterWilliams_0-1686254759644.png

 

 

You can also do it like this, its a bit less typing

var glCode1 = "";
var grGl = new GlideRecord('u_gl_codes');
if(grGl.get(obj[k].gl_code_office))
     glCode1 = grGl.u_gl_long_desc;