Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Im trying to print all variables into an email template using an email script

Ryan Norton
Giga Contributor

this is what i have, but it only prints the variables in the preview notification. not the request item the email is pertaining to.

var gr = new GlideRecord("sc_req_item");

gr.addQuery(current);

gr.query();

if(gr.next()) {

  template.print(gr.cat_item.getDisplayValue() + "\n");

  template.print("\n");

  for (key in gr.variables) {

  var v = gr.variables[key];

  if(v.getGlideObject().getQuestion().getLabel() != '') {

  if(v.getDisplayValue() != ""){

  template.space(6);

  template.print('         ' +   v.getGlideObject().getQuestion().getLabel() + " : " + v.getDisplayValue() + "\n");

  }

        }

      }

}

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Ryan,



This code snippet is intended to run on approval records. Change the current.getValue('sysapproval') part to point to the right record sys_id as needed.



 


printVars();


function printVars(){


      var set = new GlideappVariablePoolQuestionSet();


      set.setRequestID(current.getValue('sysapproval'));


      set.load();


      var vs = set.getFlatQuestions();


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


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


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


              }


      }


}


View solution in original post

5 REPLIES 5

Jamison Cote2
Mega Expert

Try using "<br/>" as opposed to "\n\n" in your mail_script. 

ServiceNow appears to prefer the HTML line break over the JS line break.