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

@lando321, name is the field name for "Name" in the User table. Typically it should display name if you are indirectly performing GlideRecord on User table if you add "name" in getDisplayValue().

Thanks for that explanation, but its still giving me the sysid unfortunately

Hi @lando321 

 

It should be the field name of the variable whose sys_id you're getting.

 

Regards,

Amit

Sandeep Rajput
Tera Patron
Tera Patron

@lando321 I am but confused with your script.

 

On the following line you are adding a sys_id filter with mvalue. Assuming mvalue contain the sys_id

                    grRefTable.addQuery('sys_id', mvalue);

On the following line you are again assigning value to mvalue. Essentially you are overwriting the sys_id value

                        mvalue = grRefTable.getDisplayValue();

 

 On the following line you are printing the mvalue

                    template.print("<td>" + mvalue + "</td>");

 

It looks like your code

var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
                    grRefTable.addQuery('sys_id', mvalue);
                    grRefTable.query();

 Doesn't return any result due to which the following line always prints a sys_id.

                    template.print("<td>" + mvalue + "</td>");

 

Hope this answers your question.