Icon

Create and Send Report

<p><strong>Create and Send a Report</strong></p><p>In this workflow, we see how to build and send a report via email using KNIME Analytics Platform.</p><p>The idea is to automatically send an email containing information about today's female gold medalist. The email body will contain bio-data and a description of the sport, event, and location. This data will dynamically change depending on today's date.</p><p>In addition, we attach an Excel file to the email with all the female gold medalists whose birthday is equal to the current date.</p><p>💡 <em>To view each node's configuration, select the node and see the configuration pane on the right side of the workflow editor.</em></p><p>We will see how to do it node by node:</p><p><strong>Excel Reader node:</strong></p><ul><li><p>Since the folder with the data is already included when you download the workflow, in the "File and Sheet" tab, we choose to "Read from" the "Current workflow data area" and select the dataset.</p></li><li><p>In the "Data Area" tab, we select to read the "Whole sheet" since the spreadsheet already has a standard format (i.e., non-empty rows or columns, etc.).</p></li></ul><p><strong>Date&amp;Time Range Creator node:</strong></p><ul><li><p>To get today's date, we use the Date&amp;Time Range Creator node. We use the execution time as starting and ending point and set Number of rows = 1.</p></li><li><p>We name the new column "current_date".</p></li></ul><p><strong>Extract month and day of month metanodes:</strong></p><p>Both metanodes are identical. Double click the metanode to open it. Inside, you will find two nodes:</p><ul><li><p><strong>Date&amp;Time Part Extractor node</strong> to extract the month and day from the date (athletes' birth dates and today's date).</p></li><li><p><strong>Column Combiner node</strong> to create a single cell containing month and day, naming it month_day.</p></li></ul><p><strong>Reference Row Filter node:</strong></p><ul><li><p>It keeps only the rows where the athlete's birthday is on the same day than today (comparing month and day).</p></li></ul><p><strong>Cell Extractor node:</strong></p><ul><li><p>Extract the current date from the table and convert it into a flow variable. We will use it in further steps to calculate a new dataset feature.</p></li></ul><p><strong>Date&amp;Time Difference:</strong></p><ul><li><p>We add a new feature to the dataset: the "years_from_birth" column. This column counts the years between the athlete's birth and today. .</p></li><li><p>In the configuration dialogue, as the first column, we select the column "born". As second column we choose a "Fixed date&amp;time", however, we overwrite the value with today's date (indicated by our previously extracted cell value). As granularity we select "Years".</p></li></ul><p><strong>Data cleaning metanode:</strong></p><p>Double click the metanode to open it. Inside, you will find four nodes:</p><ul><li><p><strong>Column Filter</strong> node to keep only the relevant columns.</p></li><li><p><strong>Number to String</strong> node to convert "years_from_birth" from number to string.</p></li><li><p><strong>Column Resorter</strong> node to change the column order.</p></li><li><p><strong>Sorter</strong> node to sort the table by years_from_birth (descending) and athlete (ascending).</p></li></ul><p><strong>Table Row to Variable node:</strong></p><ul><li><p>Convert the first row of each column into a variable (i.e., the alues of the first athlete). We will use them in the Send Email node as a placeholder in the email body.</p></li></ul><p><strong>Excel Writer node:</strong></p><ul><li><p>We write our data to a new sheet in the <em>female_gold_medalist_of_the_day.xlsx</em> file. As sheet name we use today's date (i.e., the previously extracted variable "extracted_cell" from the Cell Extractor node). So, every day we run the workflow, we append a new sheet with the execution date.</p></li><li><p>We also want to convert the file path of the Excel file into a flow variable which we call "file_path". We will use this variable in the Send Email node to attach the Excel file to the email.</p></li></ul><p><strong>Path to String (Variable) node:</strong></p><ul><li><p>The extracted file path variable is a path type variable. However, we need it to be of type string to use it in the Send Email node, which is why we are converting the "file_path" variable from path to string ("file_path_string").</p></li></ul><p><strong>Send Email node:</strong></p><ul><li><p>In the "Mail" tab, you can insert your email to try out and receive the email. In the email body (text field below), we write the body content, including some placeholders (flow variables) to render the email dynamic.</p></li><li><p>In the "Mail Host (SMTP)" tab, it depends on the Internet Service Provider (ISP) that we want to reach. In this example, we use Gmail. Below are the configurations values:</p><ul><li><p>SMTP Host: smtp.gmail.com</p></li><li><p>SMTP port: 465</p></li><li><p>We need to flag "SMTP host needs authentication."</p></li><li><p>Username: your Gmail email account.</p></li><li><p>Password: your Gmail password.</p></li><li><p>If you have 2-step Verification, you need to follow the steps explained here: https://support.google.com/accounts/answer/185833?visit_id=638125333963998850-1780931931&amp;p=InvalidSecondFactor&amp;rd=1</p></li><li><p>Connection Security: SSL</p></li></ul></li><li><p>To attach the file we previously exported with the Excel Writer node, in the "Flow Variables" tab, we use the created "file_path_string" variable to define "attachedURLs" value.</p></li></ul>

Create and Send a Report


This workflow demonstrates how to prepare data to build a report and then send it via email. The aim is to automatically send an email containing information about today's female gold medalist. The email body will contain information about the athlete and a description of the sport, event, and location. This data will dynamically change depending on today's date, so the use case also shows how to apply flow variables. In addition, the email will contain a file attachment containing a list of all the female gold medalists whose birthday is equal to today's date (day and month).

In this example, we access an Excel file containing information about all female gold medalists of the 1920-2020 Summer Olympic Games. To get today's date, we use a Date&Time Range Creator node, which is configured to create one date cell using the execution date. We perform some data manipulation, extract the day and month from the dates (without year), and calculate the age of the athletes. We apply some more data cleaning (filter columns, type conversion, sort table) and append the final dataset to a new sheet in the existing Excel file. Lastly, we configure the Send Email node by adding the email text, attaching the file, and setting up the mailing options.

Note. The Send Email node requires personal configuration input.

For a detailed overview of each node in this workflow, refer to the workflow description in the Info panel.


💡 To view each node's configuration, select the node and see the configuration pane on the right side of the workflow editor.

Setting up email configuration

Data access/input

  1. Read file located in workflow data area

  2. Create today's date

Data manipulation

  • Creating month_day column by extracting "Month (Name") and "Day of Month" from athlete's birthday and today's date

  • Filter data to keep only athletes whose birthday match today's date (month & day)

  • Calculate difference (in years) between athletes' birthdays and today

  • Clean data by filtering columns and resorting table

This node needs personal configuration inputs.

Data export

Append table as new spreadsheet to Excel file female_gold_medallist_of_the_day.xlsx

Extract month and day of month
Calculate years between athlete's birthdate and today
Date&Time Difference
First athlete datato flow variables
Table Row to Variable
Extract month and day of month
Read female goldmedalist results
Excel Reader
Path to String (Variable)
Extract current dateas a flow variable
Cell Extractor
Send the email reportand attach the Excel filegenerated before
Send Email
Create new sheet usingcurrent date as sheet name
Excel Writer
Data cleaning
Create today's date
Date&Time Range Creator
Keep only athleteswhose birthday is today
Reference Row Filter

Nodes

Extensions

Links