08-12-2024 01:18 AM
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>Email Snap HTML Table</title>
<style type="text/css"> $values.Snap {background-color:transparent;border-collapse:collapse;width:100%;} $values.Snap th,
$values.Snap td {text-align:center;border:1px solid black;padding:5px;} $values.Snap th {background-color:AntiqueWhite;}
</style>
</head>
<body>
<p>Dear SnapLogic Users:</p>
<p>This is a sample Snap email with HTML Table email type.</p>
<table class="Snap">
</table>
<p></p>
<p>Regards,</p>
<p>SnapLogic Staff</p>
</body>
</html>'
Generated Email Body:
Though it's printing the header correctly, the values are printed as lists. I want this to be a printed as a proper table. In this case 1 header and two records. Appreciate any help.
Thanks
Solved! Go to Solution.
08-19-2024 10:47 PM
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:
08-19-2024 10:47 PM
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:
08-20-2024 10:24 PM
Thanks Aditya. Your solution worked perfectly 😊