Early Access: The content on this website is provided for informational purposes only in connection with pre-General Availability Qlik Products.
All content is subject to change and is provided without warranty.
Skip to main content Skip to complementary content

Example - Creating an email report using an embedded HTML template

In this example, you will create and send a report by embedding an HTML report template directly into an email message.

Email report that you will create in this example.

The resulting email report for the example

Requirements

Step 1: Upload example sources

Refer to the example app sources here: Example materials - In-app reporting. Upload the app and data files into a space, and then reload the app. You are ready to complete the example.

Step 2: Develop the template

Create a new template

  1. In your app, use the drop down menu in the navigation bar and select Reporting.

  2. Switch to the Templates tab.

  3. In the top right, click Create newHTML template.

  4. Enter a Name for the template.

The HTML designer opens.

Add tabular data

Next, add tabular data to the template.

  1. Click Tables in the objects panel.

  2. Click Add table. A list of available sheets appears.

  3. Expand the Sales Tables sheet.

  4. Click the Plus symbol icon next to the Yearly Regional Sales chart.

  5. In the drop down menu, select Individual columns.

  6. Under Select columns to add, select All. Click Add.

    The chart is added to the template as a table structure.

  7. With the new table selected, change the following properties for the table in the objects panel:

    • Under Table settings, turn off Keep source formats.

    • Switch Display headers to Hide.

  8. In the table, add a new row above the existing row definition. Add a new line below the line that contains <tbody><tr>. Paste the following:

    <th>Order year</th>
    <th>Region</th>
    <th>Sales</th>
    </tr>
    <tr>

Style the table

Next, style the table elements by adding style definitions in the HTML head and inline styling in the table structure itself.

  1. Add a new line below the title definition for the template.

  2. Paste the following:

    <style>html { font-family: sans-serif }
    table { border: 2px solid #000000 }
    tr, th, td { border: 1px solid #000000 }
    th { font-size: large }
    td { font-size: medium }</style>
  3. Locate the line in the table structure that defines the data. It should look like this:

    <td>%%OrderYear%%</td><td>%%Region%%</td><td>%%Sales%%</td>
  4. Add style="text-align: center" to the opening tag of the first td element. The entire line should now look like this:

    <td style="text-align: center">%%OrderYear%%</td><td>%%Region%%</td><td>%%Sales%%</td>

    This aligns the text in the first column to be centered.

Adding a dynamic title

Next, create an expression to store the calculation of the year range for your sales. Then, incorporate this expression into the report title so it is embedded as the email subject.

  1. Click Variables and expressions in the objects panel.

  2. Click Add expression.

  3. In the Name field, type YearRange.

  4. In the Expression field, paste the following expression:

    = min(OrderYear)& ' - ' & max(OrderYear)
  5. Click Create.

  6. On the design surface, find the title element. Replace the entire line with the following:

    <title>Sales Report: </title>
  7. On the line you just pasted, place your cursor after Sales Report:

  8. In the objects panel, click Add expression tag.

  9. The line should now be:

    <title>Sales Report: %YearRange%%</title>

Add opening and closing statements

Next, add a salutation and opening statement, and finalize the report with a closing compliment.

  1. Add a new line below the opening body tag.

  2. Paste the following:

        <p>Hello,</p>
        <p>The table below outlines regional sales details for the requested years.</p>
    
  3. Add a new line below the line containing the closing tag for the table.

  4. Paste the following:

        <p>Regards,</p>
        <p>- Management</p>

Saving and finalizing your work

Click Save template to save your work. The completed template code should look like the following.

<html><head>
  <title>Sales Report: %%YearRange%%</title>
<style>html { font-family: sans-serif }
table { border: 2px solid #000000 }
tr, th, td { border: 1px solid #000000 }
th { font-size: large }
td { font-size: medium }</style>
  </head>
  <body>
    <p>Hello,</p>
    <p>The table below outlines regional sales details for the requested years.</p>
    <table cellspacing="0" style="border-collapse: collapse">
    <tbody><tr>
      <th>Order year</th>
      <th>Region</th>
      <th>Sales</th>
      </tr>
      <tr>
      <td style="text-align: center">%%OrderYear%%</td><td>%%Region%%</td><td>%%Sales%%</td></tr>
    </tbody></table>
    <p>Regards,</p>
    <p>- Management</p>
</body></html>

Step 3: Add a distribution list

Add a distribution list file under the Recipients or Groups tab in the app's Reporting section. Make sure you are added by email as a recipient and that the distribution list does not contain any filters or groups.

For information about distribution lists, see Creating a distribution list for your report.

Step 4: Create a report task

  1. Open the Report tasks tab in the Reporting section of the app.

  2. Click Create report task. The report task dialog opens.

  3. Enter a Title for your report task.

  4. Optionally, add a Description.

    In the Template dialog tab, click Add existing template. Select the template that you developed above.

  5. Click Next. The dialog moves to the Output tab.

  6. In the Output dialog tab, type a File name for the report output.

  7. Click Next to proceed to the Distribute dialog tab.

  8. Add yourself as a recipient to the report output.

  9. Under Email, select HTML report. This will embed the report into the email message rather than attaching it as a file.

  10. Click Next to proceed to the Schedule dialog tab.

  11. Select the default scheduling settings and click Save.

Step 5: Send the report

  1. Stay in the Report tasks tab in the Reporting section of the app.

  2. Click More actions next to the new report task.

  3. Click Send Send now.

When the email arrives, open it to see the result.

Resulting email report

The resulting email report that is sent to the user, showing the embedded HTML template rendered in the email body

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!