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

Kieran Anson
Kilo Patron

Rather than querying the variable table(s) directly, you can use GlobalServiceCatalogUtil script include to fetch the information for you as an easy to enumerate array.

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

var requestItemGR = new GlideRecord('sc_req_item');
requestItemGR.addQuery('request', current.getUniqueValue());
requestItemGR.orderBy('number');
requestItemGR.query();

var scAPI = new GlobalServiceCatalogUtil();

while (requestItemGR.next()) {

    var requestItemStage = requestItemGR.getDisplayValue('stage');
    template.print(gs.getMessage('{0}: {1}, Stage: {2}<br>', [
        requestItemGR.getDisplayValue(),
        requestItemGR.getDisplayValue('cat_item'),
        requestItemStage
    ]));

    //Get Variables using OOB API
    var reqItemVars = scAPI.getVariablesForTask(requestItemGR /*, true - if you want MRVS*/ )

    //No Vars
    if (!reqItemVars || !Array.isArray(reqItemVars) || reqItemVars.length == 0) {
        template.print('<br>');
        continue;
    }
    reqItemVars.forEach(function(variable) {
        template.print(gs.getMessage('{0}: {1}', [variable.label, variable.display_value]));
        template.print('<br>');
    });

    template.print('<br>');

}

First, thank you so much for your help this solved everything except for one field which is a drop down. The drop down box for computer profile is listed the variable name "laptop_standard" instead of the display value of "Standard Laptop", screenshot attached.

Could you go Computer Profile question and take a screenshot showing the type and the method of which choices are populated (this will either be as a related list, or under the 'type specification' tab

KieranAnson_0-1715099991626.png

 

Here you go.