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