Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Question on notification template

Mani60
Tera Contributor

HI All,
I have written one email script, whatever variable of catalog item is shown on notification with value but I am facing one issue. In single request multiple ritm attached so sc_request table notification opened on behalf The value of the variable appears repeated.
Please find attached snapshot.
Mani60_0-1714387851890.pngMani60_1-1714387911237.png

Suppose 4 ritm attached in request then here 4 time variable and answer showing , so could you help me on this only one time variable nd answer showing,
please find the attached below code which i have writeen:

 




(
function runMailScript(current, template, email, email_action, event) {

 
     var ritm = new GlideRecord("sc_req_item");
    ritm.addQuery("request", current.sys_id);
    ritm.query();
   
    while(ritm.next()) {
       
        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 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.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>');
    }
   
 

})(current, template, email, email_action, event);
 
Thanks,
Manish
1 REPLY 1

Kieran Anson
Kilo Patron

Hi Manish,

When posting code, please use the 'insert/edit code sample' option to format the text; helps with readability.

 

To clarify your intended result, for this email you want to show all the variables for the requested items, without duplication? However, how are you defining duplication? A request could have multiple RITMs, and they have individual 'requested for' so wouldn't be a  duplicate?