Fetch all variables in sc_task notifications

suru2
Tera Contributor

Hi All,

I' have one requirement to fetch catalog variables in sc_task notification for that I'm using below code but there variables and variables values are coming but it's showing multiple times with same or different information.

PFB Code which I'm using.

(function runMailScript(current, template, email, email_action, event) {
    // Add your code here
    var ritm = new GlideRecord("sc_req_item");
    ritm.addQuery("request_item", current.sys_id);
    ritm.query();

    while (ritm.next()) {

        //template.print('<b>Detalle del Elemento Pedido:</b>
        var varown = new GlideRecord('sc_item_option_mtom');
        varown.addQuery("request_item", ritm.sys_id);
        varown.addQuery("sc_item_option.value != ''null'' ");
        varown.orderBy("sc_item_option.order");
        varown.query();
        //template.print('<table border=2; style=width: 75%; color: #000000; font-family: Trebuchet MS; font-size:12px;>');
        template.print('<table cellspacing="5" cellpadding="5" width="100%" style="border-color:#000000; height:30px; border-collapse:collapse;">');

        template.print('<tr><th style="width: 35%; border:1px solid black;" align="left">Variable</th><th style="border:1px solid black;" align="left">Answer</th></tr>');

        while (varown.next()) {
            var visible = varown.sc_item_option.item_option_new.visible_summary;
            var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
            question.setValue(varown.sc_item_option.value);
            if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && question.getLabel() != "null" && question.getDisplayValue() != "undefined") {
                //template.space(4);
                template.print('<tr><td style="border:1px solid black;">' + question.getLabel() + '</td><td style="border:1px solid black;"><strong>' + question.getDisplayValue() + '</strong></td></tr>');
            }
        }
        //template.print('</table><table style=width: 90%; color: #080000; font-family: Trebuchet MS; font-size:12px;>');
        template.print('</table>');
    }
})(current, template, email, email_action, event);
PFA:-
suraj_0-1706003354972.png

 

Cloud you please help me on this to let me know the correct solution or where I'm making the mistake.

 

Thanks,

0 REPLIES 0