Prevent empty fields in email notifications

SD29
Tera Expert

Hello Experts,

I have a request regarding email notifications. How can we prevent empty fields of a catalog item from appearing in the email notifications.

Thanks,

SD.

1 ACCEPTED SOLUTION

SD29
Tera Expert

if(vs.get(i).getLabel() != '' && vs.get(i) .getDisplayValue() != '' && vs.get(i) .getDisplayValue() != 'false'


View solution in original post

8 REPLIES 8

Uncle Rob
Kilo Patron

Wrap it in a mail script that checks each field for a value before writing it


Hello Robert,



This is the message i have in my email template. Where exactly I have to do that??




Request: ${sysapproval}


Requested By: ${sysapproval.opened_by}


Requested For: ${sysapproval.requested_for}


Short Description: ${sysapproval.short_description}




<hr/>


<mail_script>


  template.print("Summary of Requested items:\n");  


  var item = new GlideRecord("sc_req_item");


  item.addQuery("request", current.sysapproval);


  item.query();


  while(item.next()) {


          template.print(item.number + ":   " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at " + item.cat_item.price.getDisplayValue() + " each \n");


          template.print("       Options:\n");


          var keys = new Array();


          var set = new GlideappVariablePoolQuestionSet();


          set.setRequestID(item.sys_id);


          set.load();


          var vs = set.getFlatQuestions();


          for (var i=0; i < vs.size(); i++) {


              if(vs.get(i).getLabel() != '') {


                    template.space(4);


                    template.print('         ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");  


              }


          }


  }


</mail_script>




Click here to view Approval Request: ${URI}


Click here to view ${sysapproval.sys_class_name}:   ${sysapproval.URI}




<hr/>


${mailto:mailto.approval}


<hr/>


${mailto:mailto.rejection}


<hr/>


In this       if(vs.get(i).getLabel() != '') { loop add the below condition




if(vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != ''){


SD29
Tera Expert

Hi Dvp,



When i use this all the non selected variables appear as shown as below, but i don't need them to be shown in the email.


Screen Shot 2017-01-24 at 9.02.06 AM.png



Please help!!



Thanks,


SD