GlideappVariablePoolQuestionSet is showing hidden fields in notification

Ajai S Nair
Giga Guru

I have a notiifcation email script which uses GlideappVariablePoolQuestionSet to display the variables in the request item.Recently i have created a catalog item and while testing i found that hidden fields used as a counter variable are being displayed inside the notification.The script which is written in email script is :

var requestedItem = current.sys_id;

var set = new GlideappVariablePoolQuestionSet();

set.setRequestID(requestedItem);

set.load();

var vs = set.getFlatQuestions();

var count = 0;                                                          

                                           

while (vs.size() > count)

{

      if (vs.get(count).getLabel() != '' && vs.get(count).getLabel() != 'null' && vs.get(count).getLabel() != 'asfd' && vs.get(count).getDisplayValue() != '' && vs.get(count).getDisplayValue() != '-- None --' && vs.get(count).getDisplayValue() != ' ')

  {

  template.print("<tr><td style='border:none;border-bottom:solid #BFBFBF 1.0pt; padding:2.9pt 2.9pt 2.9pt 2.9pt'><p align=right style='margin-bottom:0in;margin-bottom:.0001pt;text-align:right;line-height:normal'><span style='font-family:\"Arial\",sans-serif;'>");

  template.print(vs.get(count).getLabel());

  template.print("</span></p></td><td style='border:none;border-bottom:solid #BFBFBF 1.0pt;background:#E7EBF9;padding:2.9pt 2.9pt 2.9pt 2.9pt'><p style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'><b>");

  if(vs.get(count).getDisplayValue().toString().indexOf('\n') != -1){

  var text = vs.get(count).getDisplayValue().toString().split('\n');

  var textToPrint='';

  for(var k=0; k<text.length; k++){

  textToPrint = textToPrint + "<span style='font-family:\"Arial\",sans-serif;color:black;'>" + text[k] + "</span>\n";

  }

  template.print(textToPrint);

  }

  else{

  template.print("<span style='font-family:\"Arial\",sans-serif;color:black;'>");

  template.print(vs.get(count).getDisplayValue());

  template.print("</span></b></p></td></tr>");

  }

 

      }

      count = Math.floor(count + 1);

}

Could anyone hep me to solve this issue.

12 REPLIES 12

Hi Robert,



What Version of SN are you on?   I'm able to get your mail script to work in virgin instances of Jakarta, but not virgin instances of Istanbul (which is my current version).



I've raised it with HI also.



Kevin


Hey Kevin,



I have only used this in Jakarta.   I spun up my Istanbul instance this morning and confirmed your finding that isVisibleSummary() is not accessible in Istanbul.   Hopefully ServiceNow Support has a good reason as for why this was previously locked down.


Hi Team,



I raised this in HI and was able to get the method whitelisted by ServiceNow (presumably given it's going to be whitelisted in future) however the caveat was that these are ServiceNow methods and are subject to change.



I'm now struggling with some weird HTML rendering issues with my mail script in a template file.   I'm trying to make the rendering of the variables better looking by putting them in a table.   I've got a mail script called clean.request.itil.approve.role_script_1 that does this (essentially wrapping the variables in a table):



  template.print("<table style=\"font-family: arial, sans-serif;border-collapse: collapse;width: 100%;\">");


var item = new GlideRecord("sc_req_item");


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


  item.query();


  while(item.next()) {


          template.print("       <tr>");


          template.print("   <th colspan = \"2\" style= \"background-color: #f28331; color:white;border: 1px solid #dddddd;width: 50%;text-align: left;padding: 8px;\">"+item.number + ":   " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at " + item.price.getDisplayValue() + " each </th>");


          template.print("       </tr>");


          template.print("       <tr>");


          template.print("       <th style=\"border: 1px solid #dddddd;width: 50%;text-align: left;padding: 8px;\">Option</th>");


          template.print("       <th style=\"border: 1px solid #dddddd;width: 50%;text-align: left;padding: 8px;\">Selected</th>");



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


                  template.print("<tr><td style=\"border: 1px solid #dddddd;width: 50%;text-align: left;padding: 8px;\">" +   vs.get(i).getLabel() +   "</td><td   style=\"border: 1px solid #dddddd;width: 50%;text-align: left;padding: 8px;\">" + vs.get(i).getDisplayValue() + "</td></tr>");


              }


          }


  }


template.print("       </table>");



however, when I embed this script inline in my html email by using ${mail_script:clean.request.itil.approve.role_script_1} it embeds the table at the bottom of the email (after all other content).   I'm stumped as to why this might be happening - weird HTML tricks I assume, and possibly because I've got the table embedded... I'm really not sure.   It's almost like there's something in the script syntax that is making it want to put the table at the bottom.   When I look at the HTML output in sys_email, it looks like the script doesn't get enclosed in a <div>, however forcing a div around the script doesn't seem to help either.