- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 08:40 AM
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
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 12:29 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 09:05 AM
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>');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 09:11 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 09:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 09:52 AM