Table Formatted Variable Summary in an notification email script

Robert Duca
Tera Contributor

Does anyone have any examples they can share of presenting RITM variable summary in an email notification script in a table format? 

We have approvals triggered from Requested Items and are currently providing the OOTB script summary but i would like to format those results into a table format like this:

Variable 1Answer 1
Variable 2Answer 2
Variable 3Answer 3
Variable 4Answer 4
Variable 5Answer 4
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.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");  
        }
      }
  }
1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi,

you need to wrap the variables in HTML table formatting as below. I've not condensed the HTML so you can visually see the formatting.

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.price.getDisplayValue() + " each \n");
	template.print("    Options:\n");

	var set = new GlideappVariablePoolQuestionSet();
	set.setRequestID(req.sys_id);
	set.load();
	var vs = set.getFlatQuestions();
	
	template.print("<table><tbody>");

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

		if(vs.get(i).getLabel() != '') {
				
				template.print("<tr>");
					template.print("<td>");
						template.print(vs.get(i).getLabel());
					template.print("</td>");
			
					template.print("<td>");
						template.print(vs.get(i).getDisplayValue());
					template.print("</td>");
				template.print("<tr>");

		}

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

}

View solution in original post

2 REPLIES 2

Kieran Anson
Kilo Patron

Hi,

you need to wrap the variables in HTML table formatting as below. I've not condensed the HTML so you can visually see the formatting.

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.price.getDisplayValue() + " each \n");
	template.print("    Options:\n");

	var set = new GlideappVariablePoolQuestionSet();
	set.setRequestID(req.sys_id);
	set.load();
	var vs = set.getFlatQuestions();
	
	template.print("<table><tbody>");

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

		if(vs.get(i).getLabel() != '') {
				
				template.print("<tr>");
					template.print("<td>");
						template.print(vs.get(i).getLabel());
					template.print("</td>");
			
					template.print("<td>");
						template.print(vs.get(i).getDisplayValue());
					template.print("</td>");
				template.print("<tr>");

		}

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

}

thanks that worked great!