Email notification displays sys_id instead of value for referenced fields

Roberto R
Tera Contributor

Can anyone assist me with getting the fields to display correctly for non-text fields? It looks like it will display correctly only if the field is text but if it's a reference field or a drop down it's not pulling the displayed value for the variable.

 

For example (screenshot below)... the Manager/Department/Work Location variable is a lookup from the associates tables. The output is the sys_id of the selected manager/dept/location and not their display name.

 

 

 

template.print("Requested items: <br>");

var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while(gr.next()) {
    var stage = gr.stage.getDisplayValue();
    if (JSUtil.nil(stage))
        stage = gr.stage.getChoiceValue();
    template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + ", Stage: " + stage + "<br>");
    
    // Retrieve and print variables for each requested item
    var variables = new GlideRecord('sc_item_option_mtom');
    variables.addQuery('request_item', gr.sys_id);
	    variables.orderBy("sc_item_option.order");
		variables.query();
    while(variables.next()) {
        var question = variables.sc_item_option.item_option_new.getDisplayValue();
        var answer = variables.sc_item_option.value.getDisplayValue();
        template.print(question + ": " + answer + "<br>");
    }
    template.print("<br>"); // Adds a space between items for better readability
}

 

1 ACCEPTED SOLUTION

Thanks Roberto,

The two questions are slightly different, the one from the email screenshot being "Select computer profile from the dropdown" and the one in the latest screenshot being "Select a computer profile" - Perhaps one is a flow/workflow variable rather than on the actual item?

View solution in original post

7 REPLIES 7

Thanks Roberto,

The two questions are slightly different, the one from the email screenshot being "Select computer profile from the dropdown" and the one in the latest screenshot being "Select a computer profile" - Perhaps one is a flow/workflow variable rather than on the actual item?

I completely missed creating the matching variables on the catalog item from the order guide. Thank you for all of your assistance!

Jaspal Singh
Mega Patron
Mega Patron

Hi Roberto,

Try below something as below, not tested but with should be aligned to this logic

template.print("Requested items: <br>");

var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while(gr.next()) {
    var stage = gr.stage.getDisplayValue();
    if (JSUtil.nil(stage))
        stage = gr.stage.getChoiceValue();
    template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + ", Stage: " + stage + "<br>");
    
    // Retrieve and print variables for each requested item
    var variables = new GlideRecord('sc_item_option_mtom');
    variables.addQuery('request_item', gr.sys_id);
	    variables.orderBy("sc_item_option.order");
		variables.query();
    while(variables.next()) {
if(variables.sc_item_option.item_option_new.type=='8')//if reference field 
{
var question = variables.sc_item_option.item_option_new.getDisplayValue();
var answer = getDisplayNames(variables.sc_item_option.value.getDisplayValue());
template.print(question + ": " + answer + "<br>");
}
else
{
        var question = variables.sc_item_option.item_option_new.getDisplayValue();
        var answer = variables.sc_item_option.value.getDisplayValue();
        template.print(question + ": " + answer + "<br>");
    }

    template.print("<br>"); // Adds a space between items for better readability
}
}

function getDisplayNames(sysidofrecord)
{
var rec = new GlideRecord('sys_user'); 
 if(rec.get(sys_id)) {
return rec.getDisplayValue();
}
}