selected Check Box variables to display in email notification

harishdasari
Tera Guru

Hi,

We have catalog form and it has checkbox variables in it.

user while filling the form, he will select the required checkboxes, some of the checkboxes will remain un-checked.

Here requirement is to display the only checkbox variables which are checked or selected on the email notification template.

If user will not select any checkbox variable on the form, then it should not be displayed on the email notification template.

please help me how can I achieve this.

Thank you.

1 ACCEPTED SOLUTION

Hi Ankur,



This is the code I have have been using in email script, But none of the check box variables are displaying in email notification.. even though they are true. please correct me if anything wrong this code.


Thank you.



template.print('<p>Roles that Should be Assigned to the Requested User:<br />');  


  var item = new GlideRecord("sc_req_item");


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


  item.query();


  while(item.next()) {


          var keys = [];


          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() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue().toString() != 'false') {


if(vs.get(i).getLabel() != "Requested for:" && vs.get(i).getLabel() != "Opened by:" && vs.get(i).getLabel() != "Approval for")


  htmlContent += '<tr><td class="nameValue" width="30%">' + vs.get(i).getLabel() + ':<br><br></td><td width="60%" class="body_content" valign="top">' + vs.get(i).getDisplayValue() +'<br><br></td></tr>';


      }  


                    template.space(4);


                    template.print('         ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br />");  


              }


          }


View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Harish,



you need to write email notification script for this.


following link should be helpful which also has script:



Ignore any checkbox variable with a value of false in email Scripts




Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank you Ankur, I will check it and getback again.



Thanks


Hi Ankur,



This is the code I have have been using in email script, But none of the check box variables are displaying in email notification.. even though they are true. please correct me if anything wrong this code.


Thank you.



template.print('<p>Roles that Should be Assigned to the Requested User:<br />');  


  var item = new GlideRecord("sc_req_item");


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


  item.query();


  while(item.next()) {


          var keys = [];


          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() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue().toString() != 'false') {


if(vs.get(i).getLabel() != "Requested for:" && vs.get(i).getLabel() != "Opened by:" && vs.get(i).getLabel() != "Approval for")


  htmlContent += '<tr><td class="nameValue" width="30%">' + vs.get(i).getLabel() + ':<br><br></td><td width="60%" class="body_content" valign="top">' + vs.get(i).getDisplayValue() +'<br><br></td></tr>';


      }  


                    template.space(4);


                    template.print('         ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br />");  


              }


          }


Hi Harish,



Did you check by adding log statements in the code?


First run the script in background and check whether variables with true are coming or not.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader