snapping_turtl3
2 years agoNew Contributor II
Email Sender Snap - HTML Table printing grouped values together
Hi I am trying to group a SQL output as a single table using an Email Sender Snap. The flow is as follows: Mapper: Email Sender Snap Body: '<!DOCTYPE html>
<html>
<head>
<title>Emai...
- 2 years ago
Instead of using mapper, I suggest you to use the XML Generator snap together with Apache Velocity. From this dataset we can easily create desired table in mail.
Firstly, change Target field in GroupByN snap to "values".
After this, use an XML Generator Snap. Make sure your setting are same as below:
The following code goes into the XML generator snap.
<html> <head> <style> table { width: 100%; } thead th { background: black; color: white; } tbody tr:nth-child(even) { background: #D9D9D9; } td { padding: 5px; } </style> </head> <body> <p>Hi Team, </br> TEST </br> </br> <b> <table> <table border=1> <thead> <tr> <th>DEMO_KEY</th> <th>DEMO_CODE</th> <th>DEMO_DESCRIPTION</th> <th>DEMO_GROUP</th> <th>DEMO_GROUP_2</th> <th>DEMO_COUNTRY</th> </tr> </thead> <tbody> #foreach ( $values in $values ) <tr> <td>$values.DEMO_KEY</td> <td>$values.DEMO_CODE</td> <td>$values.DEMO_DESCRIPTION</td> <td>$values.DEMO_GROUP</td> <td>$values.DEMO_GROUP_2</td> <td>$values.DEMO_COUNTRY</td> </tr> #end </tbody> </table></body></html>
Next, just place an Email Sender snap, add your account settings and in the property “Email type” select “HTML text”. Once you set this, just enable the expression for the “Template body” property and use the following expression to remove the “\n” characters.
$xml.replaceAll("\n", "")
And this is the preview of email that this will generate: