cancel
Showing results for 
Search instead for 
Did you mean: 

Email Sender Snap - HTML Table printing grouped values together

snapping_turtl3
New Contributor II

Hi 

I am trying to group a SQL output as a single table using an Email Sender Snap. The flow is as follows:

snapping_turtl3_0-1723450066095.png

Mapper:

snapping_turtl3_1-1723450152003.png

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:

snapping_turtl3_3-1723450678757.png

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

1 ACCEPTED SOLUTION

aditya_gupta41
Contributor

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".

aditya_gupta41_0-1724131521016.png

After this, use an XML Generator Snap. Make sure your setting are same as below:

aditya_gupta41_1-1724131639354.png

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", "")

aditya_gupta41_2-1724132245924.png

And this is the preview of email that this will generate:

aditya_gupta41_4-1724132807821.png

 

 

View solution in original post

2 REPLIES 2

aditya_gupta41
Contributor

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".

aditya_gupta41_0-1724131521016.png

After this, use an XML Generator Snap. Make sure your setting are same as below:

aditya_gupta41_1-1724131639354.png

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", "")

aditya_gupta41_2-1724132245924.png

And this is the preview of email that this will generate:

aditya_gupta41_4-1724132807821.png

 

 

snapping_turtl3
New Contributor II

Thanks Aditya. Your solution worked perfectly 😊