How can I take the name of a pipeline dynamically using the Email Sender snap in SnapLogic?

869 Views Asked by At

I want to take the name of a pipeline coming from the input stream directly so I can use the values to generate an HTML table in the Email Sender snap and write a report without having to generate a file first, so it can be more convenient. 

My code looks something like this:

"<p>Hello,</p>" +

"<p><strong>Message</strong></p>"

+
"<table class=\"table table-striped\">
<thead class=\"thead-dark\">
  <tr>
    <th>Pipelines</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>" + $Pipeline + "</td>
  </tr>
  </tbody>
</table>"

However, my issue with this is while it does take the values from the input stream, it repeats the first row based on how many input documents there are. If I were to have 5 input documents, I would get for example Pipeline_1 repeated 5 times. The expression does not process the values after Pipeline_1.

I have tried using the $("Pipeline:contains(Pipeline_1)"); method, however, this expression doesn't work and neither does the match expression.

Any suggestions?

1

There are 1 best solutions below

0
On

You can send incoming documents as an HTML table quite easily using the Email Sender snap.

From SnapLogic Docs

For "HTML table" type, the Snap expects to find and tags inside the Template body. One Document at the input view corresponds to one row of the HTML table. For each Document, the Snap gets a map data referenced by the Table-data path property and insert a row into the HTML table of the message body. The Table-data path property can also reference an array of map data. The Snap uses the key sets of the map data to compose the column headers of the table. The Snap processes the entire stream of Documents in a batch to generate the superset of keys.

Pipeline:

Following is the test pipeline I made to demonstrate this.

Test Pipeline

Input:

Following is the Input JSON (created based on the description you provided) that I configured in the JSON Generator snap.

[
    {
        "Pipeline": "Pipeline_1",
        "State": "Completed",
        "Start_Time": "2019-12-18",
        "Documents": 1
    },
    {
        "Pipeline": "Pipeline_2",
        "State": "Completed",
        "Start_Time": "2019-12-17",
        "Documents": 200
    },
    {
        "Pipeline": "Pipeline_3",
        "State": "Completed",
        "Start_Time": "2019-12-18",
        "Documents": 10
    },
    {
        "Pipeline": "Pipeline_4",
        "State": "Failed",
        "Start_Time": "2019-12-16",
        "Documents": 25
    }
]

Configuration:

Following is an Email Template that I got from Snaplogic docs.

<!DOCTYPE html> 
<html> 
<head> 
     <title>Email Snap HTML Table</title> 
<style type="text/css"> table.Snap {background-color:transparent;border-collapse:collapse;width:100%;} table.Snap th, 
      table.Snap td {text-align:center;border:1px solid black;padding:5px;} table.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>

Configuration required other than setting the template -

  • Email Type: Set this as HTML table
  • Table-data path: Set this to $ which is the root element
  • Batch Size: Set this to the number of rows you need to send in the email at a time

Following is a screenshot of the settings I used in the Email Sender snap.

Email Sender settings

When using just $ in the Table-data path, the Snap creates an HTML table, wherein the Template Body has the HTML table tags (<table></table>). Thus, the table auto-fills with the incoming data.

Note: The document structure needs to be flat.

As far as the batch size is concerned -

If the number of Documents the Snap receives from the input view reaches the given Batch size, the Snap composes an email message with an HTML table and sends it to the server. Multiple emails are generated if needed to send out all Documents. The Snap sends the last message at the end of the pipeline execution if any number of the un-sent table rows remain.

Result:

Following is the screenshot of the mail I received.

Email

References: