Email Script Formatting

James Turney
Tera Contributor

Hello All! 

 

I'm working on an email script to display request information (not for an approval) and I'm struggling to get the information to display in a readable manner. Below is the script I have managed to piece together to display variables from the request and exclude any variables that are false or have no value. 

 printVars();

 function printVars() {

     template.print("<b>Summary of Requested Item</b>:\n");
     var requesterName;
     //var gr = new GlideRecord("sc_req_item");  
     var gr = new GlideRecord("sc_req_item");

     gr.addQuery("sys_id", current.sys_id);
     gr.query();

     //template.print("Details:\n");  

     var itemOptions = new GlideRecord('sc_item_option_mtom');
     itemOptions.addQuery('request_item', current.sys_id);
     itemOptions.orderBy('sc_item_option.order');
     itemOptions.query();
     
         // template.print('<table bgcolor="#D9E3C1" border="0" cellspacing="2">');  

         while (itemOptions.next()) {
             var visible = itemOptions.sc_item_option.item_option_new.visible_summary;

             var question = GlideappAbstractChoiceListQuestion.getQuestion(itemOptions.sc_item_option.item_option_new);
             question.setValue(itemOptions.sc_item_option.value);

             if (visible == true && question.getLabel() != '' && question.getLabel() != null && question.getDisplayValue() != '' && question.getDisplayValue() != 'false') {
                 template.print('<tr><th align="left" width="15%">' + "<span style='color:#151B54'>" + question.getLabel() + ":" + '</th></span><td>' + "<span style='color:#151B54'>" + question.getDisplayValue() + '</td></span></tr>\n');

                 if (question.getLabel() == 'Name') {
                     requesterName = question.getDisplayValue();
                 }
             }
         }
     }
 
 
 
This works as intended with displaying the needed information BUT it's all crammed together and I don't know how to separate it all and make it more legible to the person receiving this info. Ideally each piece of information would be on a separate line
 
JamesTurney_0-1710424434768.png

 

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi @James Turney , 

Please try with below updated code, html <table> tag added before and after while loop.

If this update not work for you then add boarder attribute with <table boarder=1> and check the output.

function printVars() {

     template.print("<b>Summary of Requested Item</b>:\n");
     var requesterName;
     //var gr = new GlideRecord("sc_req_item");  
     var gr = new GlideRecord("sc_req_item");

     gr.addQuery("sys_id", current.sys_id);
     gr.query();

     //template.print("Details:\n");  

     var itemOptions = new GlideRecord('sc_item_option_mtom');
     itemOptions.addQuery('request_item', current.sys_id);
     itemOptions.orderBy('sc_item_option.order');
     itemOptions.query();
     
         // template.print('<table bgcolor="#D9E3C1" border="0" cellspacing="2">');  
		template.print('<table>')
         while (itemOptions.next()) {
             var visible = itemOptions.sc_item_option.item_option_new.visible_summary;
             var question = GlideappAbstractChoiceListQuestion.getQuestion(itemOptions.sc_item_option.item_option_new);
             question.setValue(itemOptions.sc_item_option.value);

             if (visible == true && question.getLabel() != '' && question.getLabel() != null && question.getDisplayValue() != '' && question.getDisplayValue() != 'false') {
                 
				 template.print('<tr><th align="left" width="15%">' + "<span style='color:#151B54'>" + question.getLabel() + ":" + '</th></span><td>' + "<span style='color:#151B54'>" + question.getDisplayValue() + '</td></span></tr>\n');

                 if (question.getLabel() == 'Name') {
                     requesterName = question.getDisplayValue();
                 }
             }
         }
		template.print('</table>'); 
     }

 

 -Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

1 REPLY 1

AshishKM
Kilo Patron
Kilo Patron

Hi @James Turney , 

Please try with below updated code, html <table> tag added before and after while loop.

If this update not work for you then add boarder attribute with <table boarder=1> and check the output.

function printVars() {

     template.print("<b>Summary of Requested Item</b>:\n");
     var requesterName;
     //var gr = new GlideRecord("sc_req_item");  
     var gr = new GlideRecord("sc_req_item");

     gr.addQuery("sys_id", current.sys_id);
     gr.query();

     //template.print("Details:\n");  

     var itemOptions = new GlideRecord('sc_item_option_mtom');
     itemOptions.addQuery('request_item', current.sys_id);
     itemOptions.orderBy('sc_item_option.order');
     itemOptions.query();
     
         // template.print('<table bgcolor="#D9E3C1" border="0" cellspacing="2">');  
		template.print('<table>')
         while (itemOptions.next()) {
             var visible = itemOptions.sc_item_option.item_option_new.visible_summary;
             var question = GlideappAbstractChoiceListQuestion.getQuestion(itemOptions.sc_item_option.item_option_new);
             question.setValue(itemOptions.sc_item_option.value);

             if (visible == true && question.getLabel() != '' && question.getLabel() != null && question.getDisplayValue() != '' && question.getDisplayValue() != 'false') {
                 
				 template.print('<tr><th align="left" width="15%">' + "<span style='color:#151B54'>" + question.getLabel() + ":" + '</th></span><td>' + "<span style='color:#151B54'>" + question.getDisplayValue() + '</td></span></tr>\n');

                 if (question.getLabel() == 'Name') {
                     requesterName = question.getDisplayValue();
                 }
             }
         }
		template.print('</table>'); 
     }

 

 -Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution