How to eliminate spaces in the notification email body

amaradiswamy
Kilo Sage

Hi All,

I have implemented a notification to show the requests pending with the approval for than 1 day in a table. The process is working fine but in the email body it is showing more space between the content we have written and the table(contains requested item number,item,shortdescription etc.,).

And one more question   i have written thanks & regards after calling mail script in the notification but in the email body thanks & regards is populated above the table(printing the table from the mail script).

${mail_script:open.approval.reminder}

Thanks & Regards,

team

Please advice on this.

notification.JPGnotific.JPG

In the notification:

Dear User,

The following requests raised by you are waiting for the approvals in Servicenow.

${mail_script:open.approval.reminder}

In the mail script:

var outputString = "<table border='1'   style='width:500px'> <tr><th>Request number</th><th>Approver</th><th>Item</tem><th>Short description</th><th>Created on</th></tr>"; //Define table header columns, styles etc.

var uri = gs.getProperty('glide.servlet.uri');

  var reqt = new GlideRecord('sc_req_item');

  reqt.addQuery('opened_by',event.parm1);

  reqt.query();

while(reqt.next())

  {

   

  var shortd = reqt.short_description;

  var item = reqt.cat_item.getDisplayValue();

  var crea = reqt.sys_created_on;

  var appr = new GlideRecord('sysapproval_approver');

  appr.addQuery('sysapproval',reqt.sys_id);

  appr.addQuery('state','requested');

  appr.addQuery('sys_created_on','>=','2015-02-30');

  appr.orderBy('reqt.number');

    appr.query();

  while(appr.next())

  {

  outputString = outputString +"<tr><td><a href=" + uri + "sc_req_item.do?sys_id="+reqt.sys_id+">"+appr.sysapproval.getDisplayValue()+ "</a>"+" "+"</td><td width='500px'>" + appr.approver.getDisplayValue() + " "+"</td><td width='200px'>" + item + " "+"</td><td width='150px'>" + shortd + " "+"<td width='150px'>" + crea + " "+"</td></tr>"; //+ approvals.sysapproval.end_date + " "+"</td><td width='100px'>" + approvals.sysapproval.phase.getDisplayValue() + " "+"</td><td width='200px'>"+ approvals.sysapproval.assigned_to.getDisplayValue() + "</td></tr>";

  }

  }

template.print(outputString );

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Amaradi,



It looks like you may be writing incomplete HTML into the template. You create a table as part of your HTML ourputString, but you never close the table tag.



First step in troubleshooting your issue should be to ensure that the output from your mail script will be a full valid HTML table. You should add the closing table tag after your while loop.


View solution in original post

8 REPLIES 8

Hi Seeing,



I tried but no luck.



Could you please provide me the code?



Thanks in advance.



Regards,


swamy


Hi Amardi,



Post the script with your modifications. We can point out whatever additional changes you need to make.


Hi seering,



This is the modified script. It will some how manages to print Request number for only one time even though 20 approvers were there for that number. But, unable to play with row creation and hence end up with the below script.


I will be very thankful if you can help me to print all the 20 approvers(for example) in a single row.



var Approvalremaindermailreq = Class.create();


Approvalremaindermailreq.prototype = {


      initialize: function() {


      },


  items:function(numbe)


  {


  var co = 0;


  var outputString = "<table border='1'   style='width:1000px'> <tr><th>Requesteditem number</th><th>Request Number</th><th>Approver</th><th>Item</tem><th>Short description</th><th>Created on</th></tr>"; //Define table header columns, styles etc.


var uri = gs.getProperty('glide.servlet.uri');




  var reqt = new GlideRecord('sc_req_item');


  reqt.addQuery('opened_by',numbe);


  reqt.query();


while(reqt.next())


  {


 


  var shortd = reqt.short_description;


  var item = reqt.cat_item.getDisplayValue();


  var crea = reqt.sys_created_on;



  var appr = new GlideRecord('sysapproval_approver');



  appr.addQuery('sysapproval',reqt.sys_id);


  appr.addQuery('state','requested');


  appr.addQuery('sys_created_on','>=','2015-08-02');


  appr.orderBy('reqt.number');


  // appr.groupBy('reqt.number');


  //appr.addAggregate('COUNT', 'sysapproval');



  //appr.groupBy('sysapproval');





  appr.query();


  while(appr.next())


  {


  if(co == 0)


  {


  outputString = outputString +"<tr><td><a href=" + uri + "sc_req_item.do?sys_id="+reqt.sys_id+">"+appr.sysapproval.getDisplayValue()+ "</a>"+" "+"</td><td width='100px'>" + reqt.request.getDisplayValue() + " " +"</td><td width='100px'>"+ appr.approver.getDisplayValue() + " "+"</td><td width='200px'>" + item + " "+"</td><td width='150px'>" + shortd + " "+"<td width='150px'>" + crea + " "+"</td></tr>"; //+ approvals.sysapproval.end_date + " "+"</td><td width='100px'>" + approvals.sysapproval.phase.getDisplayValue() + " "+"</td><td width='200px'>"+ approvals.sysapproval.assigned_to.getDisplayValue() + "</td></tr>";


  //template.print(appr.sysapproval.getDisplayValue());


  //template.print(appr.approver.getDisplayValue());


  }


  else


  {


  outputString = outputString +"<tr><td> " + " " + "</td><td width='100px'>" + " " + " " +"</td><td width='100px'>"+ appr.approver.getDisplayValue() + " "+"</td><td width='200px'>" + item + " "+"</td><td width='150px'>" + shortd + " "+"<td width='150px'>" + crea + " "+"</td></tr>";



  }


  co++;


  }


  var co = 0;



  }



  return outputString + "</table>" ;




  },




      type: 'Approvalremaindermailreq'


}


Thanks and regards,


swamy


Hi Amaradi Swamy,



I had already done the work on your original script, so I just continued using that one. Your new one can work, but you need to make sure you are doing your string concatenation in the right places.



//Define table header columns, styles etc.


var outputString = "<table border='1' style='width:500px'><tr><th>Request number</th><th>Approver</th><th>Item</tem><th>Short description</th><th>Created on</th></tr>";


var uri = gs.getProperty('glide.servlet.uri');



var reqt = new GlideRecord('sc_req_item');


reqt.addQuery('opened_by',event.parm1);


reqt.query();



while (reqt.next()) {


  var shortd = reqt.short_description;


  var item = reqt.cat_item.getDisplayValue();


  var crea = reqt.sys_created_on;



  //one row per request


  outputString += "\t<tr>\n";


  //first cell in row is the Request Number, which doesn't change per-approver


  outputString += "\t\t<td><a href=" + uri + "sc_req_item.do?sys_id=" + reqt.sys_id + ">" + appr.sysapproval.getDisplayValue() + "</a></td>\n";


  //second cell will have all of our approvers


  outputString += "\t\t<td width='500px'>\n";


 


  //now put all of our approvers in the one cell


  var appr = new GlideRecord('sysapproval_approver');


  appr.addQuery('sysapproval',reqt.sys_id);


  appr.addQuery('state','requested');


  appr.addQuery('sys_created_on','>=','2015-02-30');


  appr.orderBy('reqt.number');


  appr.query();



  while (appr.next()) {


          //all individual approvers in one table cell, the approval


      outputString += "\t\t\t" + appr.approver.getDisplayValue() + "<br />\n";


  }



  //close our one td


  outputString += "\t\t</td>\n";


 


  //Add Item, Short Description and Created On


  outputString += "\t\t<td width='200px'>" + item + "</td>\n";


  outputString += "\t\t<td width='150px'>" + shortd + "</td>\n";


  outputString += "\t\t<td width='150px'>" + crea + "</td>\n";


 


  //finally, close our row for this requst


  outputString += "\t</tr>\n";


}



outputString += "</table>";



//output to log so you can see the final product


gs.log("Out table now looks like: ");


gs.log(templateString);



template.print(outputString);










This version also prints the table to the log so you can see it's final output. I added tabs and newlines to hopefully make it appear more readable.