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

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.


Hi seering,



Thank you so much for your reply.



After adding </table> to outputstring in while loop it worked for me perfectly



Regards,


Swamy


Hi Cory,



Thank you for your reply. After adding </table> tag to the outputstring it worked greatly.



The above script will produce the requested item and approver name. Suppose if the item has 20 approvers then as per the script 20 rows will be created for the each approver. But i want to send all the approvers(if more than 1 approvers for the item) in a single row means all the 20 approvers will be populated in "Approver" column.



I will be very greatful, if you can help me in acheiving this.



Thanks & Regards,


swamy


Hi Amaradi,



You already have what you need. Just move the creation of the ROW and the Approver TD outside of the while loop, and append only the display names of the approvers to the template string in that loop. Once the loop completes, close the TD, add in the rest of your info as you are doing, and close out the ROW and TABLE.