{"id":116,"date":"2018-02-06T06:13:35","date_gmt":"2018-02-06T14:13:35","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/html-email-reporting-with-tabular-data\/"},"modified":"2018-02-06T06:13:35","modified_gmt":"2018-02-06T14:13:35","slug":"html-email-reporting-with-tabular-data","status":"publish","type":"power-apps","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/html-email-reporting-with-tabular-data\/","title":{"rendered":"Html email reporting with tabular data"},"content":{"rendered":"
Email reporting is a great way to export or share data from a PowerApp. With the native Office 365 Outlook connection, it\u2019s easy to format an email with basic HTML to create nice looking email reports.<\/p>\n
Example<\/strong>: Let\u2019s say we have a company asset checkout system. The application needs to generate a report of items checked out by an employee and then notify the asset manager. For this scenario, we will create an email preview screen in the PowerApp with HTML tags and tabular data collected from the user\u2019s interaction. The preview is used as a direct input for the Outlook connector, and shows will be seen in the resulting email.<\/p>\n <\/a><\/p>\n <\/a><\/p>\n I\u2019m using the Asset Checkout template for the backend data.<\/p>\n Once the user has selected the items they will be checking out, the tabular data we will use to populate the email are identified (in this example, the items are objects the user selects and are saved to a Collection called \u2018Cart\u2019). With the target data in its own Collection, we can easily wrap the data in HTML tags that can be used to format the email.<\/p>\n \u00a0<\/a>\u00a0<\/a><\/p>\n To send a simple email, we can declare the user, list the items being checked out by the user, the date checked out, and a return date.<\/p>\n \u00a0<\/a><\/p>\n Use the \u2018HTML text\u2019 control to preview what you can send as an input to the Office 365 Outlook connector (under Insert > Text > HTML text). In the HtmlText property of the HTML text control, we can combine the application\u2019s data with HTML tags to format into a nice-looking report with the tabular data in the Cart Collection. In our example we combine the user\u2019s information, the current date, a return date (1 month from today), and the actual tabular data items with HTML tags. Let\u2019s look at the different syntax and functions used in the HtmlText property displayed below:<\/p>\n <\/a><\/p>\n <\/a><\/p>\n \u00a0<\/p>\n Use the ampersand (\u2019&\u2019) character (or alternatively the Concatenate() function) to combine text and data. Here we combine the row label followed with the associated datum joined with an ampersand like so:<\/p>\n “<b> Employee: <\/b>” & User.FullName & \u201c<br>\u201d<\/strong><\/p>\n \u00a0<\/p>\n You can use any HTML tags to markup text in the HTML text control. All HTML tags must be in double quotes to be interpreted correctly by PowerApps. Here are details on some tags being used in the example above:<\/p>\n A good reference for HTML tags and basics can be found at ww3 schools here: https:\/\/www.w3schools.com\/html\/<\/a><\/p>\n \u00a0<\/p>\n Use the Concat() function to join data rows within a Collection. In this example, we used the Collection \u2018Cart\u2019, so the first argument in Concat() is the Collection\u2019s name, \u2018Cart\u2019.<\/p>\n <\/a><\/p>\n The second argument in Concat() are the values that will be displayed. This includes the field names and any additional text or characters we add to the argument. In our case we are showing the ProductName and ProductId columns, so the second argument concatenates the two table fields by their respective column names.<\/p>\n We also number the items in the table by concatenating the \u2018list item\u2019 HTML tag (\u2019<li>\u2019) into the second field of this Concat() call. Since the list items are inside two option list (<ol>) tags, the items will be numbered automatically.<\/p>\n \u00a0<\/p>\n Connect to the Office 365 Outlook connector<\/p>\n Do this in View > Data sources in the top ribbons. If it\u2019s not in the list of connections when you click \u2018+ Add data source\u2019, then select \u2018+ New connection\u2019. Scroll until you see the \u2018Office 365 Outlook\u2019 connector, click it, then click \u2018Create\u2019 to add it to the app\u2019s data sources.<\/p>\n <\/a><\/p>\n \u00a0<\/p>\n Create a button control where the OnSelect property will send out the email with the HTML body text we\u2019ve just configured.<\/p>\n In the OnSelect property of the button, type in \u2018Office365.SendEmail(\u2018, and intellisense will provide the list of up to 4 parameters and details needed to complete the method:<\/p>\n <\/a><\/p>\n <\/a><\/p>\n \u00a0<\/p>\n The possibilities are endless with HTML reporting. You can get creative and make simple data look more sophisticated with additional formatting, colors, and other controls such as tables.<\/p>\n <\/a><\/p>\nGenerate the email body.<\/h1>\n
Joining data, variables and static text<\/h2>\n
HTML tags<\/h2>\n
\n
\n<ol>
\n\t\u00a0\u00a0\u00a0 <li> item1<\/em> <\/li>
\n\t\u00a0\u00a0\u00a0 <li> item2<\/em> <\/li>
\n\t\u00a0\u00a0\u00a0 <li> item1<\/em> <\/li>
\n\t<\/ol><\/strong><\/li>\n<\/ul>\nFormatting the Collection data<\/h2>\n
Send the email with the Office 365 Outlook connector<\/h1>\n
Setup the send email button<\/h1>\n
\n
\n<\/a>
\n\t\u00a0<\/li>\n
\n<\/a>
\n\t\u00a0<\/li>\n
\n<\/a>
\n\t\u00a0<\/li>\n
\n<\/a><\/li>\n<\/ul>\n