Reference fields in my email script are printing the sysid's instead of the display value

lando321
Tera Contributor

Can anyone spot what i am doing wrong with this portion of the my emails script? I have a reference field, i want to print the display value of the field, but its displaying the sysid

 

Script:

// Check if the value is from the reference field
                if (itemVars.sc_item_option.item_option_new.type == '8') {
                    var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
                    grRefTable.addQuery('sys_id', mvalue);
                    grRefTable.query();
                    if (grRefTable.next()) {
                        mvalue = grRefTable.getDisplayValue();
                    }
					//updated on 8/27/24
                    template.print("<td>" + mvalue + "</td>");
                    template.print("</tr>");
                }
8 REPLIES 8

Ehab Pilloor
Mega Sage

Hi @lando321

Try using 

// Check if the value is from the reference field
                if (itemVars.sc_item_option.item_option_new.type == '8') {
                    var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
                    grRefTable.addQuery('sys_id', mvalue);
                    grRefTable.query();
                    if (grRefTable.next()) {
                        mvalue = grRefTable.getDisplayValue("name");
                    }
					//updated on 8/27/24
                    template.print("<td>" + mvalue + "</td>");
                    template.print("</tr>");
                }

 

Regards,

Ehab

 

Apologies, i left some vital information out. This script is being used across multiple catalog items. i updated the line in the script, but it still returned the sys id

Amit Pandey
Kilo Sage

Hi @lando321 

 

Try this-

 

mvalue = grRefTable.getDisplayValue("name");

 

Regards,

Amit

@Amit Pandey i tried that, but still getting the sysid, should that "name" actually be the name of the variable?